Note that there are some explanatory texts on larger screens.

plurals
  1. POForkJoinPool stalls during invokeAll/join
    primarykey
    data
    text
    <p>I try to use a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html" rel="nofollow noreferrer">ForkJoinPool</a> to parallelize my CPU intensive calculations. My understanding of a ForkJoinPool is, that it continues to work as long as any task is available to be executed. Unfortunately I frequently observed worker threads idling/waiting, thus not all CPU are kept busy. Sometimes I even observed additional worker threads.</p> <p>I did not expect this, as I strictly tried to use <a href="http://en.wikipedia.org/wiki/Non-blocking_algorithm" rel="nofollow noreferrer">non blocking</a> tasks. My observation is very similar to those of <a href="https://stackoverflow.com/questions/9677506/forkjoinpool-seems-to-waste-a-thread">ForkJoinPool seems to waste a thread</a>. After debugging a lot into ForkJoinPool I have a guess: </p> <p>I used invokeAll() to distribute work over a list of subtasks. After invokeAll() finished to execute the first task itself it starts joining the other ones. This works fine, until the next task to join is on top of the executing queue. Unfortunately I submitted additional tasks asynchronously without joining them. I expected the ForkJoin framework to continue executing those task first and than turn back to joining any remaining tasks.</p> <p>But it seems not to work this way. Instead the worker thread gets stalled calling wait() until the task waiting for gets ready (presumably executed by an other worker thread). I did not verify this, but it seems to be a general flaw of calling join().</p> <p>ForkJoinPool provides an <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html#ForkJoinPool%28int,%20java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory,%20java.lang.Thread.UncaughtExceptionHandler,%20boolean%29" rel="nofollow noreferrer">asyncMode</a>, but this is a global parameter and can not be used for individual submissions. But I like to see my asynchronously forked tasks to be executed soon.</p> <p>So, why does ForkJoinTask.doJoin() not simply executes any available task on top of its queue until it gets ready (either executed by itself or stolen by others)? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload