[concurrency-interest] Composing ForkJoin tasks

Gregg Wonderly gregg at cytetech.com
Wed Jul 22 11:31:28 EDT 2009


Doug Lea wrote:
> Rich Hickey wrote:
>> There are many instances in FJ where it states "This method may be
>> invoked only from within ForkJoinTask computations." Is
>> ForkJoinTask.getPool() the correct way to detect when one is within a
>> ForkJoinTask computation?
> 
> Yes. The reason there is no other method is just that
> no name for such a method seems to be better than writing
> if (ForkJoinTask.getPool() == null)...
> 
> If you can think of one, feel free to suggest it.

The only obvious thing to me is to just provide something like the following

public static boolean inForkJoinPool() {
	return getPool() == null;
}

Convenience methods, with useful names, can be helpful in many cases to better 
convey that you are detecting a predictable situation rather than looking for a 
bad situation where null checks generally seem to appear.

Gregg Wonderly


More information about the Concurrency-interest mailing list