23 |
|
* An {@link ExecutorService} for running {@link ForkJoinTask}s. |
24 |
|
* A {@code ForkJoinPool} provides the entry point for submissions |
25 |
|
* from non-{@code ForkJoinTask}s, as well as management and |
26 |
< |
* monitoring operations. |
26 |
> |
* monitoring operations. |
27 |
|
* |
28 |
|
* <p>A {@code ForkJoinPool} differs from other kinds of {@link |
29 |
|
* ExecutorService} mainly by virtue of employing |
82 |
|
* |
83 |
|
* <p><b>Implementation notes</b>: This implementation restricts the |
84 |
|
* maximum number of running threads to 32767. Attempts to create |
85 |
< |
* pools with greater than the maximum result in |
85 |
> |
* pools with greater than the maximum number result in |
86 |
|
* {@code IllegalArgumentException}. |
87 |
|
* |
88 |
+ |
* <p>This implementation rejects submitted tasks (that is, by throwing |
89 |
+ |
* {@link RejectedExecutionException}) only when the pool is shut down. |
90 |
+ |
* |
91 |
|
* @since 1.7 |
92 |
|
* @author Doug Lea |
93 |
|
*/ |
115 |
|
* Returns a new worker thread operating in the given pool. |
116 |
|
* |
117 |
|
* @param pool the pool this thread works in |
118 |
< |
* @throws NullPointerException if pool is null |
118 |
> |
* @throws NullPointerException if the pool is null |
119 |
|
*/ |
120 |
|
public ForkJoinWorkerThread newThread(ForkJoinPool pool); |
121 |
|
} |
387 |
|
* |
388 |
|
* @param parallelism the parallelism level |
389 |
|
* @throws IllegalArgumentException if parallelism less than or |
390 |
< |
* equal to zero |
390 |
> |
* equal to zero, or greater than implementation limit |
391 |
|
* @throws SecurityException if a security manager exists and |
392 |
|
* the caller is not permitted to modify threads |
393 |
|
* because it does not hold {@link |
403 |
|
* thread factory. |
404 |
|
* |
405 |
|
* @param factory the factory for creating new threads |
406 |
< |
* @throws NullPointerException if factory is null |
406 |
> |
* @throws NullPointerException if the factory is null |
407 |
|
* @throws SecurityException if a security manager exists and |
408 |
|
* the caller is not permitted to modify threads |
409 |
|
* because it does not hold {@link |
420 |
|
* @param parallelism the parallelism level |
421 |
|
* @param factory the factory for creating new threads |
422 |
|
* @throws IllegalArgumentException if parallelism less than or |
423 |
< |
* equal to zero, or greater than implementation limit |
424 |
< |
* @throws NullPointerException if factory is null |
423 |
> |
* equal to zero, or greater than implementation limit |
424 |
> |
* @throws NullPointerException if the factory is null |
425 |
|
* @throws SecurityException if a security manager exists and |
426 |
|
* the caller is not permitted to modify threads |
427 |
|
* because it does not hold {@link |
597 |
|
* |
598 |
|
* @param task the task |
599 |
|
* @return the task's result |
600 |
< |
* @throws NullPointerException if task is null |
601 |
< |
* @throws RejectedExecutionException if pool is shut down |
600 |
> |
* @throws NullPointerException if the task is null |
601 |
> |
* @throws RejectedExecutionException if the task cannot be |
602 |
> |
* scheduled for execution |
603 |
|
*/ |
604 |
|
public <T> T invoke(ForkJoinTask<T> task) { |
605 |
|
doSubmit(task); |
610 |
|
* Arranges for (asynchronous) execution of the given task. |
611 |
|
* |
612 |
|
* @param task the task |
613 |
< |
* @throws NullPointerException if task is null |
614 |
< |
* @throws RejectedExecutionException if pool is shut down |
613 |
> |
* @throws NullPointerException if the task is null |
614 |
> |
* @throws RejectedExecutionException if the task cannot be |
615 |
> |
* scheduled for execution |
616 |
|
*/ |
617 |
|
public void execute(ForkJoinTask<?> task) { |
618 |
|
doSubmit(task); |
620 |
|
|
621 |
|
// AbstractExecutorService methods |
622 |
|
|
623 |
+ |
/** |
624 |
+ |
* @throws NullPointerException if the task is null |
625 |
+ |
* @throws RejectedExecutionException if the task cannot be |
626 |
+ |
* scheduled for execution |
627 |
+ |
*/ |
628 |
|
public void execute(Runnable task) { |
629 |
|
ForkJoinTask<?> job; |
630 |
|
if (task instanceof ForkJoinTask<?>) // avoid re-wrap |
634 |
|
doSubmit(job); |
635 |
|
} |
636 |
|
|
637 |
+ |
/** |
638 |
+ |
* @throws NullPointerException if the task is null |
639 |
+ |
* @throws RejectedExecutionException if the task cannot be |
640 |
+ |
* scheduled for execution |
641 |
+ |
*/ |
642 |
|
public <T> ForkJoinTask<T> submit(Callable<T> task) { |
643 |
|
ForkJoinTask<T> job = ForkJoinTask.adapt(task); |
644 |
|
doSubmit(job); |
645 |
|
return job; |
646 |
|
} |
647 |
|
|
648 |
+ |
/** |
649 |
+ |
* @throws NullPointerException if the task is null |
650 |
+ |
* @throws RejectedExecutionException if the task cannot be |
651 |
+ |
* scheduled for execution |
652 |
+ |
*/ |
653 |
|
public <T> ForkJoinTask<T> submit(Runnable task, T result) { |
654 |
|
ForkJoinTask<T> job = ForkJoinTask.adapt(task, result); |
655 |
|
doSubmit(job); |
656 |
|
return job; |
657 |
|
} |
658 |
|
|
659 |
+ |
/** |
660 |
+ |
* @throws NullPointerException if the task is null |
661 |
+ |
* @throws RejectedExecutionException if the task cannot be |
662 |
+ |
* scheduled for execution |
663 |
+ |
*/ |
664 |
|
public ForkJoinTask<?> submit(Runnable task) { |
665 |
|
ForkJoinTask<?> job; |
666 |
|
if (task instanceof ForkJoinTask<?>) // avoid re-wrap |
676 |
|
* |
677 |
|
* @param task the task to submit |
678 |
|
* @return the task |
679 |
+ |
* @throws NullPointerException if the task is null |
680 |
|
* @throws RejectedExecutionException if the task cannot be |
681 |
|
* scheduled for execution |
656 |
– |
* @throws NullPointerException if the task is null |
682 |
|
*/ |
683 |
|
public <T> ForkJoinTask<T> submit(ForkJoinTask<T> task) { |
684 |
|
doSubmit(task); |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
+ |
/** |
690 |
+ |
* @throws NullPointerException {@inheritDoc} |
691 |
+ |
* @throws RejectedExecutionException {@inheritDoc} |
692 |
+ |
*/ |
693 |
|
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) { |
694 |
|
ArrayList<ForkJoinTask<T>> forkJoinTasks = |
695 |
|
new ArrayList<ForkJoinTask<T>>(tasks.size()); |
1607 |
|
while (spareStack == null || !tryResumeSpare(dec)) { |
1608 |
|
int counts = workerCounts; |
1609 |
|
if (dec || (dec = casWorkerCounts(counts, --counts))) { |
1581 |
– |
// CAS cheat |
1610 |
|
if (!needSpare(counts, maintainParallelism)) |
1611 |
|
break; |
1612 |
|
if (joinMe.status < 0) |