Loading...
Good evening from Devon,
I do not remember missing a single one of my children's birthdays. With 4 kiddos, each born in different months, that is not an easy feat to achieve. I've often had to say "no" to Java conferences and paid work.
Tomorrow is my daughter's 13th birthday and I'm in Sidmouth, England, due to circumstances beyond our control. I will only get home on Sunday.
Also, tomorrow is the first Thursday of the month, and that means - "Heinz's Happy Hour" webinar at 16:00 UTC. We do those every month. https://www.javaspecialists.eu/webinars/
So what are we talking about? That is a mystery. Or rather: we are going to try solve a threading mystery together. As of writing, I do not know the solution. It has all the signs of a race condition, that manifests itself as a resource deadlock.
Here is the puzzle:
import java.util.concurrent.*;
import java.util.stream.*;
public class ForkJoinPuzzle {
public static void main(String... args) {
System.out.println("Forkjoin pool size: " +
ForkJoinPool.getCommonPoolParallelism());
parallelStream().forEach(val -> process());
}
private static void process() {
try {
String processor = Thread.currentThread().getName();
System.out.println("Processing: " + processor);
Runnable updateTask = () ->
parallelStream().forEach(value -> {
System.out.println("Updating: " +
Thread.currentThread().getName() +
" " + ForkJoinPool.commonPool());
});
Thread thread = new Thread(updateTask,
"Worker for " + processor);
thread.start();
System.out.println("Waiting: " + processor);
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
private static IntStream parallelStream() {
return IntStream.range(0,
Runtime.getRuntime().availableProcessors()).parallel();
}
}
This is based on some code send on the Concurrency Interest Mailing List, heavily stripped down though.
Perhaps you already know the answer to the puzzle?
Or maybe you'd like to hear more? In that case, see you tomorrow so we can try figure it out together.
Join us by signing up for our Happy Hour Series 3 :
https://www.javaspecialists.eu/webinars/
Kind regards
Heinz
If you no longer wish to receive our emails, click the link below:
https://iw127.infusionsoft.com/app/optOut/8/a6ca3d5100f0d052/8539550/264ba6e2d59f8bf4
Cretesoft Limited 77 Strovolos Ave Strovolos, Lefkosia 2018 Cyprus
Loading...
Loading...