[concurrency-interest] ForkJoinPool.managedBlock() not spawning new thread

Doug Lea dl at cs.oswego.edu
Fri Jul 20 06:23:25 EDT 2012


On 07/19/12 15:05, Alex Lam S.L. wrote:

> For the record, I went with the following approach instead:
>
>    class QueueBlocker<V>  implements ForkJoinPool.ManagedBlocker {
>      ...
>
>      public boolean block() throws InterruptedException {
>        if (Task.steal()) {
>          return false;
>        } else {
>          value = queue.take();
>          return true;
>        }
>      }
>    }
>

Yes. We cannot do anything like this in general, because
the steals here might violate task dependencies -- joining
the stolen task could block waiting for the current action
to finish, which it never will. But so long
as you know that this is not possible, it can work well.

-Doug




More information about the Concurrency-interest mailing list