ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ForkJoinTask.java (file contents):
Revision 1.3 by jsr166, Sun Jul 26 17:48:58 2009 UTC vs.
Revision 1.4 by jsr166, Wed Jul 29 02:35:47 2009 UTC

# Line 23 | Line 23 | import java.util.WeakHashMap;
23   * <p> A "main" ForkJoinTask begins execution when submitted to a
24   * {@link ForkJoinPool}. Once started, it will usually in turn start
25   * other subtasks.  As indicated by the name of this class, many
26 < * programs using ForkJoinTasks employ only methods {@code fork}
27 < * and {@code join}, or derivatives such as
28 < * {@code invokeAll}.  However, this class also provides a number
29 < * of other methods that can come into play in advanced usages, as
30 < * well as extension mechanics that allow support of new forms of
31 < * fork/join processing.
26 > * programs using ForkJoinTasks employ only methods {@code fork} and
27 > * {@code join}, or derivatives such as {@code invokeAll}.  However,
28 > * this class also provides a number of other methods that can come
29 > * into play in advanced usages, as well as extension mechanics that
30 > * allow support of new forms of fork/join processing.
31   *
32   * <p>A ForkJoinTask is a lightweight form of {@link Future}.  The
33   * efficiency of ForkJoinTasks stems from a set of restrictions (that
# Line 92 | Line 91 | import java.util.WeakHashMap;
91   * lightweight task scheduling framework, and so cannot be overridden.
92   * Developers creating new basic styles of fork/join processing should
93   * minimally implement {@code protected} methods
94 < * {@code exec}, {@code setRawResult}, and
95 < * {@code getRawResult}, while also introducing an abstract
94 > * {@link #exec}, {@link #setRawResult}, and
95 > * {@link #getRawResult}, while also introducing an abstract
96   * computational method that can be implemented in its subclasses,
97   * possibly relying on other {@code protected} methods provided
98   * by this class.
# Line 650 | Line 649 | public abstract class ForkJoinTask<V> im
649      }
650  
651      /**
652 <     * Returns true if the computation performed by this task has
653 <     * completed (or has been cancelled).
652 >     * Returns {@code true} if the computation performed by this task
653 >     * has completed (or has been cancelled).
654       *
655 <     * @return true if this computation has completed
655 >     * @return {@code true} if this computation has completed
656       */
657      public final boolean isDone() {
658          return status < 0;
659      }
660  
661      /**
662 <     * Returns true if this task was cancelled.
662 >     * Returns {@code true} if this task was cancelled.
663       *
664 <     * @return true if this task was cancelled
664 >     * @return {@code true} if this task was cancelled
665       */
666      public final boolean isCancelled() {
667          return (status & COMPLETION_MASK) == CANCELLED;
# Line 671 | Line 670 | public abstract class ForkJoinTask<V> im
670      /**
671       * Asserts that the results of this task's computation will not be
672       * used. If a cancellation occurs before attempting to execute this
673 <     * task, then execution will be suppressed, {@code isCancelled}
674 <     * will report true, and {@code join} will result in a
673 >     * task, execution will be suppressed, {@link #isCancelled}
674 >     * will report true, and {@link #join} will result in a
675       * {@code CancellationException} being thrown. Otherwise, when
676       * cancellation races with completion, there are no guarantees
677 <     * about whether {@code isCancelled} will report true, whether
678 <     * {@code join} will return normally or via an exception, or
679 <     * whether these behaviors will remain consistent upon repeated
677 >     * about whether {@code isCancelled} will report {@code true},
678 >     * whether {@code join} will return normally or via an exception,
679 >     * or whether these behaviors will remain consistent upon repeated
680       * invocation.
681       *
682       * <p>This method may be overridden in subclasses, but if so, must
# Line 687 | Line 686 | public abstract class ForkJoinTask<V> im
686       * <p> This method is designed to be invoked by <em>other</em>
687       * tasks. To terminate the current task, you can just return or
688       * throw an unchecked exception from its computation method, or
689 <     * invoke {@code completeExceptionally}.
689 >     * invoke {@link #completeExceptionally}.
690       *
691       * @param mayInterruptIfRunning this value is ignored in the
692       * default implementation because tasks are not in general
693       * cancelled via interruption
694       *
695 <     * @return true if this task is now cancelled
695 >     * @return {@code true} if this task is now cancelled
696       */
697      public boolean cancel(boolean mayInterruptIfRunning) {
698          setCompletion(CANCELLED);
# Line 701 | Line 700 | public abstract class ForkJoinTask<V> im
700      }
701  
702      /**
703 <     * Returns true if this task threw an exception or was cancelled.
703 >     * Returns {@code true} if this task threw an exception or was cancelled.
704       *
705 <     * @return true if this task threw an exception or was cancelled
705 >     * @return {@code true} if this task threw an exception or was cancelled
706       */
707      public final boolean isCompletedAbnormally() {
708          return (status & COMPLETION_MASK) < NORMAL;
# Line 714 | Line 713 | public abstract class ForkJoinTask<V> im
713       * CancellationException if cancelled, or null if none or if the
714       * method has not yet completed.
715       *
716 <     * @return the exception, or null if none
716 >     * @return the exception, or {@code null} if none
717       */
718      public final Throwable getException() {
719          int s = status & COMPLETION_MASK;
# Line 877 | Line 876 | public abstract class ForkJoinTask<V> im
876       * Returns the pool hosting the current task execution, or null
877       * if this task is executing outside of any ForkJoinPool.
878       *
879 <     * @return the pool, or null if none
879 >     * @return the pool, or {@code null} if none
880       */
881      public static ForkJoinPool getPool() {
882          Thread t = Thread.currentThread();
# Line 908 | Line 907 | public abstract class ForkJoinTask<V> im
907       * result in exceptions or errors, possibly including
908       * ClassCastException.
909       *
910 <     * @return true if unforked
910 >     * @return {@code true} if unforked
911       */
912      public boolean tryUnfork() {
913          return ((ForkJoinWorkerThread) Thread.currentThread())
# Line 948 | Line 947 | public abstract class ForkJoinTask<V> im
947      // Extension methods
948  
949      /**
950 <     * Returns the result that would be returned by {@code join},
951 <     * even if this task completed abnormally, or null if this task is
952 <     * not known to have been completed.  This method is designed to
953 <     * aid debugging, as well as to support extensions. Its use in any
954 <     * other context is discouraged.
950 >     * Returns the result that would be returned by {@link #join}, even
951 >     * if this task completed abnormally, or {@code null} if this task
952 >     * is not known to have been completed.  This method is designed
953 >     * to aid debugging, as well as to support extensions. Its use in
954 >     * any other context is discouraged.
955       *
956 <     * @return the result, or null if not completed
956 >     * @return the result, or {@code null} if not completed
957       */
958      public abstract V getRawResult();
959  
# Line 973 | Line 972 | public abstract class ForkJoinTask<V> im
972       * called otherwise. The return value controls whether this task
973       * is considered to be done normally. It may return false in
974       * asynchronous actions that require explicit invocations of
975 <     * {@code complete} to become joinable. It may throw exceptions
975 >     * {@link #complete} to become joinable. It may throw exceptions
976       * to indicate abnormal exit.
977       *
978 <     * @return true if completed normally
978 >     * @return {@code true} if completed normally
979       * @throws Error or RuntimeException if encountered during computation
980       */
981      protected abstract boolean exec();
# Line 992 | Line 991 | public abstract class ForkJoinTask<V> im
991       * #inForkJoinPool}). Attempts to invoke in other contexts result
992       * in exceptions or errors, possibly including ClassCastException.
993       *
994 <     * @return the next task, or null if none are available
994 >     * @return the next task, or {@code null} if none are available
995       */
996      protected static ForkJoinTask<?> peekNextLocalTask() {
997          return ((ForkJoinWorkerThread) Thread.currentThread())
# Line 1009 | Line 1008 | public abstract class ForkJoinTask<V> im
1008       * contexts result in exceptions or errors, possibly including
1009       * ClassCastException.
1010       *
1011 <     * @return the next task, or null if none are available
1011 >     * @return the next task, or {@code null} if none are available
1012       */
1013      protected static ForkJoinTask<?> pollNextLocalTask() {
1014          return ((ForkJoinWorkerThread) Thread.currentThread())
# Line 1030 | Line 1029 | public abstract class ForkJoinTask<V> im
1029       * result in exceptions or errors, possibly including
1030       * ClassCastException.
1031       *
1032 <     * @return a task, or null if none are available
1032 >     * @return a task, or {@code null} if none are available
1033       */
1034      protected static ForkJoinTask<?> pollTask() {
1035          return ((ForkJoinWorkerThread) Thread.currentThread())
# Line 1085 | Line 1084 | public abstract class ForkJoinTask<V> im
1084       * Save the state to a stream.
1085       *
1086       * @serialData the current run status and the exception thrown
1087 <     * during execution, or null if none
1087 >     * during execution, or {@code null} if none
1088       * @param s the stream
1089       */
1090      private void writeObject(java.io.ObjectOutputStream s)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines