之前说到ForkJoinPool的初始化,以及Task定义的方式,现在说说这个task是怎么启动的。从我们一般写代码的话,只会这样写一句:
mainPool.invoke(task);
就是调用了mainPool的invoke()方法,但是这个方法做了些什么呢?看如下代码:
public <T> T invoke(ForkJoinTask<T> task) {
Thread t = Thread.currentThread();
if (task == null)
throw new NullPointerException();
if (shutdown)
throw new RejectedExecutionException();
if ((t instanceof ForkJoinWorkerThread) &&a