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.35 by jsr166, Sat Aug 1 21:17:11 2009 UTC vs.
Revision 1.41 by jsr166, Mon Aug 3 01:11:58 2009 UTC

# Line 21 | Line 21 | import java.util.concurrent.atomic.Atomi
21  
22   /**
23   * An {@link ExecutorService} for running {@link ForkJoinTask}s.
24 < * A ForkJoinPool provides the entry point for submissions from
25 < * non-ForkJoinTasks, as well as management and monitoring operations.
26 < * Normally a single ForkJoinPool is used for a large number of
27 < * submitted tasks. Otherwise, use would not usually outweigh the
28 < * construction and bookkeeping overhead of creating a large set of
29 < * threads.
24 > * A {@code ForkJoinPool} provides the entry point for submissions
25 > * from non-{@code ForkJoinTask}s, as well as management and
26 > * monitoring operations.  Normally a single {@code ForkJoinPool} is
27 > * used for a large number of submitted tasks. Otherwise, use would
28 > * not usually outweigh the construction and bookkeeping overhead of
29 > * creating a large set of threads.
30   *
31 < * <p>ForkJoinPools differ from other kinds of Executors mainly in
32 < * that they provide <em>work-stealing</em>: all threads in the pool
33 < * attempt to find and execute subtasks created by other active tasks
34 < * (eventually blocking if none exist). This makes them efficient when
35 < * most tasks spawn other subtasks (as do most ForkJoinTasks), as well
36 < * as the mixed execution of some plain Runnable- or Callable- based
37 < * activities along with ForkJoinTasks. When setting {@linkplain
38 < * #setAsyncMode async mode}, a ForkJoinPool may also be appropriate
39 < * for use with fine-grained tasks that are never joined. Otherwise,
40 < * other ExecutorService implementations are typically more
31 > * <p>{@code ForkJoinPool}s differ from other kinds of {@link
32 > * Executor}s mainly in that they provide <em>work-stealing</em>: all
33 > * threads in the pool attempt to find and execute subtasks created by
34 > * other active tasks (eventually blocking if none exist). This makes
35 > * them efficient when most tasks spawn other subtasks (as do most
36 > * {@code ForkJoinTask}s), as well as the mixed execution of some
37 > * plain {@code Runnable}- or {@code Callable}- based activities along
38 > * with {@code ForkJoinTask}s. When setting {@linkplain #setAsyncMode
39 > * async mode}, a {@code ForkJoinPool} may also be appropriate for use
40 > * with fine-grained tasks that are never joined. Otherwise, other
41 > * {@code ExecutorService} implementations are typically more
42   * appropriate choices.
43   *
44 < * <p>A ForkJoinPool may be constructed with a given parallelism level
45 < * (target pool size), which it attempts to maintain by dynamically
46 < * adding, suspending, or resuming threads, even if some tasks are
47 < * waiting to join others. However, no such adjustments are performed
48 < * in the face of blocked IO or other unmanaged synchronization. The
49 < * nested {@link ManagedBlocker} interface enables extension of
50 < * the kinds of synchronization accommodated.  The target parallelism
51 < * level may also be changed dynamically ({@link #setParallelism})
52 < * and thread construction can be limited using methods
53 < * {@link #setMaximumPoolSize} and/or
54 < * {@link #setMaintainsParallelism}.
44 > * <p>A {@code ForkJoinPool} may be constructed with a given
45 > * parallelism level (target pool size), which it attempts to maintain
46 > * by dynamically adding, suspending, or resuming threads, even if
47 > * some tasks are waiting to join others. However, no such adjustments
48 > * are performed in the face of blocked IO or other unmanaged
49 > * synchronization. The nested {@link ManagedBlocker} interface
50 > * enables extension of the kinds of synchronization accommodated.
51 > * The target parallelism level may also be changed dynamically
52 > * ({@link #setParallelism}) and thread construction can be limited
53 > * using methods {@link #setMaximumPoolSize} and/or {@link
54 > * #setMaintainsParallelism}.
55   *
56   * <p>In addition to execution and lifecycle control methods, this
57   * class provides status check methods (for example
# Line 62 | Line 63 | import java.util.concurrent.atomic.Atomi
63   * <p><b>Implementation notes</b>: This implementation restricts the
64   * maximum number of running threads to 32767. Attempts to create
65   * pools with greater than the maximum result in
66 < * IllegalArgumentExceptions.
66 > * {@code IllegalArgumentException}.
67   *
68   * @since 1.7
69   * @author Doug Lea
# Line 342 | Line 343 | public class ForkJoinPool extends Abstra
343      // Constructors
344  
345      /**
346 <     * Creates a ForkJoinPool with a pool size equal to the number of
347 <     * processors available on the system, using the default
348 <     * ForkJoinWorkerThreadFactory.
346 >     * Creates a {@code ForkJoinPool} with a pool size equal to the
347 >     * number of processors available on the system, using the
348 >     * {@linkplain #defaultForkJoinWorkerThreadFactory default thread factory}.
349       *
350       * @throws SecurityException if a security manager exists and
351       *         the caller is not permitted to modify threads
# Line 357 | Line 358 | public class ForkJoinPool extends Abstra
358      }
359  
360      /**
361 <     * Creates a ForkJoinPool with the indicated parallelism level
362 <     * threads and using the default ForkJoinWorkerThreadFactory.
361 >     * Creates a {@code ForkJoinPool} with the indicated parallelism level
362 >     * threads and using the
363 >     * {@linkplain #defaultForkJoinWorkerThreadFactory default thread factory}.
364       *
365       * @param parallelism the number of worker threads
366       * @throws IllegalArgumentException if parallelism less than or
# Line 373 | Line 375 | public class ForkJoinPool extends Abstra
375      }
376  
377      /**
378 <     * Creates a ForkJoinPool with parallelism equal to the number of
379 <     * processors available on the system and using the given
380 <     * ForkJoinWorkerThreadFactory.
378 >     * Creates a {@code ForkJoinPool} with parallelism equal to the
379 >     * number of processors available on the system and using the
380 >     * given thread factory.
381       *
382       * @param factory the factory for creating new threads
383       * @throws NullPointerException if factory is null
# Line 389 | Line 391 | public class ForkJoinPool extends Abstra
391      }
392  
393      /**
394 <     * Creates a ForkJoinPool with the given parallelism and factory.
394 >     * Creates a {@code ForkJoinPool} with the given parallelism and
395 >     * thread factory.
396       *
397       * @param parallelism the targeted number of worker threads
398       * @param factory the factory for creating new threads
# Line 423 | Line 426 | public class ForkJoinPool extends Abstra
426       * Creates a new worker thread using factory.
427       *
428       * @param index the index to assign worker
429 <     * @return new worker, or null of factory failed
429 >     * @return new worker, or null if factory failed
430       */
431      private ForkJoinWorkerThread createWorker(int index) {
432          Thread.UncaughtExceptionHandler h = ueh;
# Line 578 | Line 581 | public class ForkJoinPool extends Abstra
581       * @throws NullPointerException if task is null
582       * @throws RejectedExecutionException if pool is shut down
583       */
584 <    public <T> void execute(ForkJoinTask<T> task) {
584 >    public void execute(ForkJoinTask<?> task) {
585          doSubmit(task);
586      }
587  
# Line 787 | Line 790 | public class ForkJoinPool extends Abstra
790       * Setting this value has no effect on current pool size. It
791       * controls construction of new threads.
792       *
793 <     * @throws IllegalArgumentException if negative or greater then
793 >     * @throws IllegalArgumentException if negative or greater than
794       * internal implementation limit
795       */
796      public void setMaximumPoolSize(int newMax) {
# Line 955 | Line 958 | public class ForkJoinPool extends Abstra
958      }
959  
960      /**
961 <     * Returns an estimate of the number tasks submitted to this pool
962 <     * that have not yet begun executing. This method takes time
961 >     * Returns an estimate of the number of tasks submitted to this
962 >     * pool that have not yet begun executing.  This method takes time
963       * proportional to the number of submissions.
964       *
965       * @return the number of queued submissions
# Line 990 | Line 993 | public class ForkJoinPool extends Abstra
993       * Removes all available unexecuted submitted and forked tasks
994       * from scheduling queues and adds them to the given collection,
995       * without altering their execution status. These may include
996 <     * artificially generated or wrapped tasks. This method is designed
997 <     * to be invoked only when the pool is known to be
996 >     * artificially generated or wrapped tasks. This method is
997 >     * designed to be invoked only when the pool is known to be
998       * quiescent. Invocations at other times may not remove all
999       * tasks. A failure encountered while attempting to add elements
1000       * to collection {@code c} may result in elements being in
# Line 1741 | Line 1744 | public class ForkJoinPool extends Abstra
1744       * Method {@code isReleasable} must return {@code true} if
1745       * blocking is not necessary. Method {@code block} blocks the
1746       * current thread if necessary (perhaps internally invoking
1747 <     * {@code isReleasable} before actually blocking.).
1747 >     * {@code isReleasable} before actually blocking).
1748       *
1749       * <p>For example, here is a ManagedBlocker based on a
1750       * ReentrantLock:
# Line 1780 | Line 1783 | public class ForkJoinPool extends Abstra
1783  
1784      /**
1785       * Blocks in accord with the given blocker.  If the current thread
1786 <     * is a ForkJoinWorkerThread, this method possibly arranges for a
1787 <     * spare thread to be activated if necessary to ensure parallelism
1788 <     * while the current thread is blocked.  If
1789 <     * {@code maintainParallelism} is {@code true} and the pool supports
1790 <     * it ({@link #getMaintainsParallelism}), this method attempts to
1791 <     * maintain the pool's nominal parallelism. Otherwise it activates
1792 <     * a thread only if necessary to avoid complete starvation. This
1793 <     * option may be preferable when blockages use timeouts, or are
1794 <     * almost always brief.
1786 >     * is a {@link ForkJoinWorkerThread}, this method possibly
1787 >     * arranges for a spare thread to be activated if necessary to
1788 >     * ensure parallelism while the current thread is blocked.
1789 >     *
1790 >     * <p>If {@code maintainParallelism} is {@code true} and the pool
1791 >     * supports it ({@link #getMaintainsParallelism}), this method
1792 >     * attempts to maintain the pool's nominal parallelism. Otherwise
1793 >     * it activates a thread only if necessary to avoid complete
1794 >     * starvation. This option may be preferable when blockages use
1795 >     * timeouts, or are almost always brief.
1796       *
1797 <     * <p> If the caller is not a ForkJoinTask, this method is behaviorally
1798 <     * equivalent to
1797 >     * <p>If the caller is not a {@link ForkJoinTask}, this method is
1798 >     * behaviorally equivalent to
1799       *  <pre> {@code
1800       * while (!blocker.isReleasable())
1801       *   if (blocker.block())
1802       *     return;
1803       * }</pre>
1804 <     * If the caller is a ForkJoinTask, then the pool may first
1805 <     * be expanded to ensure parallelism, and later adjusted.
1804 >     *
1805 >     * If the caller is a {@code ForkJoinTask}, then the pool may
1806 >     * first be expanded to ensure parallelism, and later adjusted.
1807       *
1808       * @param blocker the blocker
1809       * @param maintainParallelism if {@code true} and supported by

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines