Why don't you read the documentation that you linked to?
invoke
Commences performing this task, awaits its completion if necessary,
and returns its result, or throws an (unchecked) RuntimeException or
Error if the underlying computation did so.
Seems pretty clear to me, awaits its completion if necessary is rather unambiguously saying that this method is not asynchronous.
get
Waits if necessary for the computation to complete, and then retrieves
its result.
This method is inherited from Future
, this method is analogous to join
. From the javadoc for join
:
Returns the result of the computation when it is done. This method
differs from get() in that abnormal completion results in
RuntimeException or Error, not ExecutionException, and that interrupts
of the calling thread do not cause the method to abruptly return by
throwing InterruptedException.
So, to use the Fork/Join framework you need to call fork
which is asynchronous. Then do the other part of the task locally. Then call join
.
The basic premise of the fork join framework is that it is used in divide and conquer algorithms that can be multi threaded.
The idea is that you split you task into two discrete units and then pass one off to another ForkJoinTask
via fork
- this runs concurrently to the current Thread
. You then process the other unit in the current Thread
. When you are done you call join
on the first task to ensure that you get the result from it.
Calling invoke
waits for the invoked task to complete. So your method in now not asynchronous. You just run all of your parts sequentially somewhat defeating the point of fork/join.
So if you were to call x.fork().join()
it would be the same as x.invoke()
but the whole point is that you do work on the current Thread
between invoking fork
and join
.