Can I use the work-stealing behaviour of ForkJoinPool to avoid a thread starvation deadlock?
- 阅读更多 关于 Can I use the work-stealing behaviour of ForkJoinPool to avoid a thread starvation deadlock?
A thread starvation deadlock occurs in a normal thread pool if all the threads in the pool are waiting for queued tasks in the same pool to complete. ForkJoinPool avoids this problem by stealing work from other threads from inside the join() call, rather than simply waiting. For example: private static class ForkableTask extends RecursiveTask<Integer> { private final CyclicBarrier barrier; ForkableTask(CyclicBarrier barrier) { this.barrier = barrier; } @Override protected Integer compute() { try { barrier.await(); return 1; } catch (InterruptedException | BrokenBarrierException e) { throw new