Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding invokeAll method of the ForkJoinTask

While I was reading the javadoc about ForkJoinTask I came across the following statement:

This method may be invoked only from within ForkJoinPool computations (as may be determined using method inForkJoinPool()). Attempts to invoke in other contexts result in exceptions or errors, possibly including ClassCastException.

What's not clear to me is what ForkJoinContext means here. I know what static context means, for example. It clearly defines in the JLS 8.1.3 as follows (Emphasize's mine):

A statement or expression occurs in a static context if and only if the innermost method, constructor, instance initializer, static initializer, field initializer, or explicit constructor invocation statement enclosing the statement or expression is a static method, a static initializer, the variable initializer of a static variable, or an explicit constructor invocation statement (§8.8.7).

like image 700
St.Antario Avatar asked Dec 02 '25 15:12

St.Antario


1 Answers

The context being discussed here is not static/non-static context.

It means that the method must be called from a thread which belongs to the ForkJoinPool.

So it must be called from a recursive task. Calling from anywhere else might cause exceptions/errors.

like image 136
Tanmay Patil Avatar answered Dec 05 '25 06:12

Tanmay Patil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!