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

Comparing jsr166/src/jsr166y/ForkJoinTask.java (file contents):
Revision 1.12 by jsr166, Wed Jul 22 01:36:51 2009 UTC vs.
Revision 1.13 by dl, Wed Jul 22 19:04:11 2009 UTC

# Line 81 | Line 81 | import java.lang.reflect.*;
81   * class. While these methods have {@code public} access (to allow
82   * instances of different task subclasses to call each others
83   * methods), some of them may only be called from within other
84 < * ForkJoinTasks. Attempts to invoke them in other contexts result in
85 < * exceptions or errors possibly including ClassCastException.
84 > * ForkJoinTasks (as may be determined using method {@link
85 > * #inForkJoinPool}).  Attempts to invoke them in other contexts
86 > * result in exceptions or errors possibly including
87 > * ClassCastException.
88   *
89   * <p>Most base support methods are {@code final} because their
90   * implementations are intrinsically tied to the underlying
# Line 482 | Line 484 | public abstract class ForkJoinTask<V> im
484       * necessarily enforced, it is a usage error to fork a task more
485       * than once unless it has completed and been reinitialized.  This
486       * method may be invoked only from within ForkJoinTask
487 <     * computations. Attempts to invoke in other contexts result in
488 <     * exceptions or errors possibly including ClassCastException.
487 >     * computations (as may be determined using method {@link
488 >     * #inForkJoinPool}). Attempts to invoke in other contexts result
489 >     * in exceptions or errors possibly including ClassCastException.
490       */
491      public final void fork() {
492          ((ForkJoinWorkerThread)(Thread.currentThread())).pushTask(this);
# Line 522 | Line 525 | public abstract class ForkJoinTask<V> im
525      /**
526       * Forks both tasks, returning when {@code isDone} holds for
527       * both of them or an exception is encountered. This method may be
528 <     * invoked only from within ForkJoinTask computations. Attempts to
528 >     * invoked only from within ForkJoinTask computations (as may be
529 >     * determined using method {@link #inForkJoinPool}). Attempts to
530       * invoke in other contexts result in exceptions or errors
531       * possibly including ClassCastException.
532       *
# Line 541 | Line 545 | public abstract class ForkJoinTask<V> im
545       * Forks the given tasks, returning when {@code isDone} holds
546       * for all of them. If any task encounters an exception, others
547       * may be cancelled.  This method may be invoked only from within
548 <     * ForkJoinTask computations. Attempts to invoke in other contexts
549 <     * result in exceptions or errors possibly including ClassCastException.
550 <     *
548 >     * ForkJoinTask computations (as may be determined using method
549 >     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
550 >     * result in exceptions or errors possibly including
551 >     * ClassCastException.
552       * @param tasks the array of tasks
553       * @throws NullPointerException if tasks or any element are null
554       * @throws RuntimeException or Error if any task did so
# Line 585 | Line 590 | public abstract class ForkJoinTask<V> im
590       * Forks all tasks in the collection, returning when
591       * {@code isDone} holds for all of them. If any task
592       * encounters an exception, others may be cancelled.  This method
593 <     * may be invoked only from within ForkJoinTask
594 <     * computations. Attempts to invoke in other contexts result in
595 <     * exceptions or errors possibly including ClassCastException.
593 >     * may be invoked only from within ForkJoinTask computations (as
594 >     * may be determined using method {@link
595 >     * #inForkJoinPool}). Attempts to invoke in other contexts resul!t
596 >     * in exceptions or errors possibly including ClassCastException.
597       *
598       * @param tasks the collection of tasks
599       * @throws NullPointerException if tasks or any element are null
# Line 773 | Line 779 | public abstract class ForkJoinTask<V> im
779       * current task and that of any other task that might be executed
780       * while helping. (This usually holds for pure divide-and-conquer
781       * tasks). This method may be invoked only from within
782 <     * ForkJoinTask computations. Attempts to invoke in other contexts
783 <     * result in exceptions or errors possibly including ClassCastException.
782 >     * ForkJoinTask computations (as may be determined using method
783 >     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
784 >     * resul!t in exceptions or errors possibly including
785 >     * ClassCastException.
786       *
787       * @return the computed result
788       */
# Line 788 | Line 796 | public abstract class ForkJoinTask<V> im
796      /**
797       * Possibly executes other tasks until this task is ready.  This
798       * method may be invoked only from within ForkJoinTask
799 <     * computations. Attempts to invoke in other contexts result in
800 <     * exceptions or errors possibly including ClassCastException.
799 >     * computations (as may be determined using method {@link
800 >     * #inForkJoinPool}). Attempts to invoke in other contexts resul!t
801 >     * in exceptions or errors possibly including ClassCastException.
802       */
803      public final void quietlyHelpJoin() {
804          if (status >= 0) {
# Line 855 | Line 864 | public abstract class ForkJoinTask<V> im
864  
865      /**
866       * Returns the pool hosting the current task execution, or null
867 <     * if this task is executing outside of any pool.
867 >     * if this task is executing outside of any ForkJoinPool.
868       *
869 <     * @return the pool, or null if none
869 >     * @return the pool, or null if none.
870       */
871      public static ForkJoinPool getPool() {
872          Thread t = Thread.currentThread();
# Line 866 | Line 875 | public abstract class ForkJoinTask<V> im
875      }
876  
877      /**
878 +     * Returns true if the current thread is executing as a
879 +     * ForkJoinPool computation.
880 +     * @return <code>true</code> if the current thread is executing as a
881 +     * ForkJoinPool computation, or false otherwise
882 +     */
883 +    public static boolean inForkJoinPool() {
884 +        return Thread.currentThread() instanceof ForkJoinWorkerThread;
885 +    }
886 +
887 +    /**
888       * Tries to unschedule this task for execution. This method will
889       * typically succeed if this task is the most recently forked task
890       * by the current thread, and has not commenced executing in
891       * another thread.  This method may be useful when arranging
892       * alternative local processing of tasks that could have been, but
893       * were not, stolen. This method may be invoked only from within
894 <     * ForkJoinTask computations. Attempts to invoke in other contexts
895 <     * result in exceptions or errors possibly including ClassCastException.
894 >     * ForkJoinTask computations (as may be determined using method
895 >     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
896 >     * result in exceptions or errors possibly including
897 >     * ClassCastException.
898       *
899       * @return true if unforked
900       */
# Line 954 | Line 975 | public abstract class ForkJoinTask<V> im
975       * be polled or executed next.  This method is designed primarily
976       * to support extensions, and is unlikely to be useful otherwise.
977       * This method may be invoked only from within ForkJoinTask
978 <     * computations. Attempts to invoke in other contexts result in
979 <     * exceptions or errors possibly including ClassCastException.
978 >     * computations (as may be determined using method {@link
979 >     * #inForkJoinPool}). Attempts to invoke in other contexts result
980 >     * in exceptions or errors possibly including ClassCastException.
981       *
982       * @return the next task, or null if none are available
983       */
# Line 968 | Line 990 | public abstract class ForkJoinTask<V> im
990       * queued by the current thread but not yet executed.  This method
991       * is designed primarily to support extensions, and is unlikely to
992       * be useful otherwise.  This method may be invoked only from
993 <     * within ForkJoinTask computations. Attempts to invoke in other
993 >     * within ForkJoinTask computations (as may be determined using
994 >     * method {@link #inForkJoinPool}). Attempts to invoke in other
995       * contexts result in exceptions or errors possibly including
996       * ClassCastException.
997       *
# Line 987 | Line 1010 | public abstract class ForkJoinTask<V> im
1010       * of the pool this task is operating in.  This method is designed
1011       * primarily to support extensions, and is unlikely to be useful
1012       * otherwise.  This method may be invoked only from within
1013 <     * ForkJoinTask computations. Attempts to invoke in other contexts
1013 >     * ForkJoinTask computations (as may be determined using method
1014 >     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
1015       * result in exceptions or errors possibly including
1016       * ClassCastException.
1017       *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines