[concurrency-interest] ForkJoinPool cap on number of threads

Martin Buchholz martinrb at google.com
Wed Mar 25 15:07:06 EDT 2015


TIL that ForkJoinPool.ForkJoinWorkerThreadFactory does not implement
ThreadFactory!
Nevertheless, we can align the specs to allow the former to return null,
like the latter.
This seems like small progress:

Index: src/main/java/util/concurrent/ForkJoinPool.java
===================================================================
RCS file:
/export/home/jsr166/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinPool.java,v
retrieving revision 1.240
diff -u -r1.240 ForkJoinPool.java
--- src/main/java/util/concurrent/ForkJoinPool.java 23 Feb 2015 20:54:08
-0000 1.240
+++ src/main/java/util/concurrent/ForkJoinPool.java 25 Mar 2015 19:03:36
-0000
@@ -681,7 +681,8 @@
          * Returns a new worker thread operating in the given pool.
          *
          * @param pool the pool this thread works in
-         * @return the new worker thread
+         * @return the new worker thread, or {@code null} if the request
+         *         to create a thread is rejected
          * @throws NullPointerException if the pool is null
          */
         public ForkJoinWorkerThread newThread(ForkJoinPool pool);


On Wed, Mar 25, 2015 at 11:23 AM, Martin Buchholz <martinrb at google.com>
wrote:

>
>
> On Wed, Mar 25, 2015 at 8:24 AM, Luke Sandberg <lukeisandberg at gmail.com>
> wrote:
>
>> Thanks!
>>
>> Looks like i can have my ForkJoinThreadFactory return null to limit
>> active threads. (it would be nice if that was documented on
>> ForkJoinThreadFactory)
>>
>>
> I agree that we should make that clearer - there are existing snippets of
> javadoc, but we should add something (perhaps even sample code) showing how
> to impose a limit.
>
>
>> In that snapshot it looks like the maxSpares limitation only applies to
>> the common pool, is there a plan to add a standard maxSize mechanism for
>> user pools?
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20150325/1928d24e/attachment.html>


More information about the Concurrency-interest mailing list