[concurrency-interest] Single-threaded ForkJoinPool

Doug Lea dl at cs.oswego.edu
Sat Feb 6 15:43:45 EST 2016


On 02/06/2016 05:21 AM, Viktor Klang wrote:
> What happens if you supply it with a thread factory which only allows a single
> thread to be alive at a time, and returns null if it already has returned a
> still living thread?
>

Yes, this will work if you are positive that only one thread
is required for liveness. FJ sometimes conservatively creates
threads when it cannot itself guarantee liveness (for example,
when GC or other system load causes stalls). But it will
respond to null factory returns by rechecking, not failing.
unless a thread really is needed to maintain liveness, in which
case the program may livelock. To reduce transient near-livelock,
you might want to place a Thread.yield() call before the
"return null" in the factory.

-Doug


> --
> Cheers,
>>
> On Feb 6, 2016 05:19, "cowwoc" <cowwoc at bbs.darktech.org
> <mailto:cowwoc at bbs.darktech.org>> wrote:
>
>     Hi,
>
>     Is this the correct mailing list for discussing ForkJoinPool in JDK9? If
>     not, please point me to the right place.
>
>     I have a feature request for ForkJoinPool which doesn't seem to be possible
>     to implement without a JDK change: http://stackoverflow.com/q/34012134/14731
>
>     Specifically, I need to be able to an application that uses Random and
>     ForkJoinPool in a deterministic manner when debugging/profiling but run
>     full-speed in normal execution mode. I have all the moving parts nailing
>     down except for ForkJoinPool.
>
>     If I create ForkJoinPool with a parallelism of 1, sometimes I see two worker
>     threads getting used. I am guessing that this is caused by
>     ForkJoinTask.get() invoking ForkJoinPool.common.externalHelpComplete(), but
>     maybe something else is going on.
>
>     Is there a way for me to guarantee that ForkJoinThread will use exactly 1
>     worker thread, no less, no more? Would you like me to file a formal feature
>     request?
>
>     Thank you,
>     Gili
>
>
>
>     --
>     View this message in context:
>     http://jsr166-concurrency.10961.n7.nabble.com/Single-threaded-ForkJoinPool-tp13232.html
>     Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
>     _______________________________________________
>     Concurrency-interest mailing list
>     Concurrency-interest at cs.oswego.edu <mailto:Concurrency-interest at cs.oswego.edu>
>     http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>





More information about the Concurrency-interest mailing list