ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.43 by jsr166, Tue Aug 4 00:55:13 2009 UTC vs.
Revision 1.49 by jsr166, Mon Nov 16 04:57:09 2009 UTC

# Line 23 | Line 23 | import java.util.concurrent.atomic.Atomi
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
# Line 45 | Line 45 | import java.util.concurrent.atomic.Atomi
45   * #setMaintainsParallelism}, the pool attempts to maintain this
46   * number of active (or available) threads by dynamically adding,
47   * suspending, or resuming internal worker threads, even if some tasks
48 < * are waiting to join others. However, no such adjustments are
49 < * performed in the face of blocked IO or other unmanaged
48 > * are stalled waiting to join others. However, no such adjustments
49 > * are performed in the face of blocked IO or other unmanaged
50   * synchronization. The nested {@link ManagedBlocker} interface
51   * enables extension of the kinds of synchronization accommodated.
52   * The target parallelism level may also be changed dynamically
# Line 82 | Line 82 | import java.util.concurrent.atomic.Atomi
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   */
# Line 112 | Line 115 | public class ForkJoinPool extends Abstra
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      }
# Line 384 | Line 387 | public class ForkJoinPool extends Abstra
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
# Line 400 | Line 403 | public class ForkJoinPool extends Abstra
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
# Line 417 | Line 420 | public class ForkJoinPool extends Abstra
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
# Line 594 | Line 597 | public class ForkJoinPool extends Abstra
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);
# Line 606 | Line 610 | public class ForkJoinPool extends Abstra
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);
# Line 615 | Line 620 | public class ForkJoinPool extends Abstra
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
# Line 624 | Line 634 | public class ForkJoinPool extends Abstra
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
# Line 651 | Line 676 | public class ForkJoinPool extends Abstra
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);
# Line 661 | Line 686 | public class ForkJoinPool extends Abstra
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());
# Line 804 | Line 833 | public class ForkJoinPool extends Abstra
833  
834      /**
835       * Returns the maximum number of threads allowed to exist in the
836 <     * pool.  Unless set using {@link #setMaximumPoolSize}, the
836 >     * pool. Unless set using {@link #setMaximumPoolSize}, the
837       * maximum is an implementation-defined value designed only to
838       * prevent runaway growth.
839       *
# Line 816 | Line 845 | public class ForkJoinPool extends Abstra
845  
846      /**
847       * Sets the maximum number of threads allowed to exist in the
848 <     * pool.  Setting this value has no effect on current pool
849 <     * size. It controls construction of new threads.
848 >     * pool. The given value should normally be greater than or equal
849 >     * to the {@link #getParallelism parallelism} level. Setting this
850 >     * value has no effect on current pool size. It controls
851 >     * construction of new threads.
852       *
853       * @throws IllegalArgumentException if negative or greater than
854       * internal implementation limit
# Line 1075 | Line 1106 | public class ForkJoinPool extends Abstra
1106      }
1107  
1108      private static String runStateToString(int rs) {
1109 <        switch(rs) {
1109 >        switch (rs) {
1110          case RUNNING: return "Running";
1111          case SHUTDOWN: return "Shutting down";
1112          case TERMINATING: return "Terminating";
# Line 1576 | Line 1607 | public class ForkJoinPool extends Abstra
1607          while (spareStack == null || !tryResumeSpare(dec)) {
1608              int counts = workerCounts;
1609              if (dec || (dec = casWorkerCounts(counts, --counts))) {
1579                // CAS cheat
1610                  if (!needSpare(counts, maintainParallelism))
1611                      break;
1612                  if (joinMe.status < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines