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.9 by jsr166, Mon Jul 20 22:26:03 2009 UTC vs.
Revision 1.10 by jsr166, Tue Jul 21 00:15:13 2009 UTC

# Line 141 | Line 141 | public abstract class ForkJoinTask<V> im
141      /**
142       * Table of exceptions thrown by tasks, to enable reporting by
143       * callers. Because exceptions are rare, we don't directly keep
144 <     * them with task objects, but instead us a weak ref table.  Note
144 >     * them with task objects, but instead use a weak ref table.  Note
145       * that cancellation exceptions don't appear in the table, but are
146       * instead recorded as status values.
147 <     * Todo: Use ConcurrentReferenceHashMap
147 >     * TODO: Use ConcurrentReferenceHashMap
148       */
149      static final Map<ForkJoinTask<?>, Throwable> exceptionMap =
150          Collections.synchronizedMap
# Line 153 | Line 153 | public abstract class ForkJoinTask<V> im
153      // within-package utilities
154  
155      /**
156 <     * Get current worker thread, or null if not a worker thread
156 >     * Gets current worker thread, or null if not a worker thread.
157       */
158      static ForkJoinWorkerThread getWorker() {
159          Thread t = Thread.currentThread();
# Line 176 | Line 176 | public abstract class ForkJoinTask<V> im
176      // Setting completion status
177  
178      /**
179 <     * Mark completion and wake up threads waiting to join this task.
179 >     * Marks completion and wakes up threads waiting to join this task.
180 >     *
181       * @param completion one of NORMAL, CANCELLED, EXCEPTIONAL
182       */
183      final void setCompletion(int completion) {
# Line 255 | Line 256 | public abstract class ForkJoinTask<V> im
256      /**
257       * Sets status to indicate there is joiner, then waits for join,
258       * surrounded with pool notifications.
259 +     *
260       * @return status upon exit
261       */
262      private int awaitDone(ForkJoinWorkerThread w, boolean maintainParallelism) {
# Line 297 | Line 299 | public abstract class ForkJoinTask<V> im
299      }
300  
301      /**
302 <     * Notify pool that thread is unblocked. Called by signalled
302 >     * Notifies pool that thread is unblocked. Called by signalled
303       * threads when woken by non-FJ threads (which is atypical).
304       */
305      private void adjustPoolCountsOnUnblock(ForkJoinPool pool) {
# Line 308 | Line 310 | public abstract class ForkJoinTask<V> im
310      }
311  
312      /**
313 <     * Notify pool to adjust counts on cancelled or timed out wait
313 >     * Notifies pool to adjust counts on cancelled or timed out wait.
314       */
315      private void adjustPoolCountsOnCancelledWait(ForkJoinPool pool) {
316          if (pool != null) {
# Line 323 | Line 325 | public abstract class ForkJoinTask<V> im
325      }
326  
327      /**
328 <     * Handle interruptions during waits.
328 >     * Handles interruptions during waits.
329       */
330      private void onInterruptedWait() {
331          ForkJoinWorkerThread w = getWorker();
# Line 342 | Line 344 | public abstract class ForkJoinTask<V> im
344      }
345  
346      /**
347 <     * Throws the exception associated with status s;
347 >     * Throws the exception associated with status s.
348 >     *
349       * @throws the exception
350       */
351      private void reportException(int s) {
# Line 355 | Line 358 | public abstract class ForkJoinTask<V> im
358      }
359  
360      /**
361 <     * Returns result or throws exception using j.u.c.Future conventions
361 >     * Returns result or throws exception using j.u.c.Future conventions.
362       * Only call when isDone known to be true.
363       */
364      private V reportFutureResult()
# Line 375 | Line 378 | public abstract class ForkJoinTask<V> im
378  
379      /**
380       * Returns result or throws exception using j.u.c.Future conventions
381 <     * with timeouts
381 >     * with timeouts.
382       */
383      private V reportTimedFutureResult()
384          throws InterruptedException, ExecutionException, TimeoutException {
# Line 396 | Line 399 | public abstract class ForkJoinTask<V> im
399  
400      /**
401       * Calls exec, recording completion, and rethrowing exception if
402 <     * encountered. Caller should normally check status before calling
402 >     * encountered. Caller should normally check status before calling.
403 >     *
404       * @return true if completed normally
405       */
406      private boolean tryExec() {
# Line 414 | Line 418 | public abstract class ForkJoinTask<V> im
418  
419      /**
420       * Main execution method used by worker threads. Invokes
421 <     * base computation unless already complete
421 >     * base computation unless already complete.
422       */
423      final void quietlyExec() {
424          if (status >= 0) {
# Line 430 | Line 434 | public abstract class ForkJoinTask<V> im
434      }
435  
436      /**
437 <     * Calls exec, recording but not rethrowing exception
438 <     * Caller should normally check status before calling
437 >     * Calls exec(), recording but not rethrowing exception.
438 >     * Caller should normally check status before calling.
439 >     *
440       * @return true if completed normally
441       */
442      private boolean tryQuietlyInvoke() {
# Line 447 | Line 452 | public abstract class ForkJoinTask<V> im
452      }
453  
454      /**
455 <     * Cancel, ignoring any exceptions it throws
455 >     * Cancels, ignoring any exceptions it throws.
456       */
457      final void cancelIgnoringExceptions() {
458          try {
# Line 499 | Line 504 | public abstract class ForkJoinTask<V> im
504      /**
505       * Commences performing this task, awaits its completion if
506       * necessary, and return its result.
507 +     *
508       * @throws Throwable (a RuntimeException, Error, or unchecked
509 <     * exception) if the underlying computation did so.
509 >     * exception) if the underlying computation did so
510       * @return the computed result
511       */
512      public final V invoke() {
# Line 516 | Line 522 | public abstract class ForkJoinTask<V> im
522       * invoked only from within ForkJoinTask computations. Attempts to
523       * invoke in other contexts result in exceptions or errors
524       * possibly including ClassCastException.
525 +     *
526       * @param t1 one task
527       * @param t2 the other task
528       * @throws NullPointerException if t1 or t2 are null
529 <     * @throws RuntimeException or Error if either task did so.
529 >     * @throws RuntimeException or Error if either task did so
530       */
531      public static void invokeAll(ForkJoinTask<?>t1, ForkJoinTask<?> t2) {
532          t2.fork();
# Line 533 | Line 540 | public abstract class ForkJoinTask<V> im
540       * may be cancelled.  This method may be invoked only from within
541       * ForkJoinTask computations. Attempts to invoke in other contexts
542       * result in exceptions or errors possibly including ClassCastException.
543 +     *
544       * @param tasks the array of tasks
545 <     * @throws NullPointerException if tasks or any element are null.
546 <     * @throws RuntimeException or Error if any task did so.
545 >     * @throws NullPointerException if tasks or any element are null
546 >     * @throws RuntimeException or Error if any task did so
547       */
548      public static void invokeAll(ForkJoinTask<?>... tasks) {
549          Throwable ex = null;
# Line 577 | Line 585 | public abstract class ForkJoinTask<V> im
585       * may be invoked only from within ForkJoinTask
586       * computations. Attempts to invoke in other contexts result in
587       * exceptions or errors possibly including ClassCastException.
588 +     *
589       * @param tasks the collection of tasks
590 <     * @throws NullPointerException if tasks or any element are null.
591 <     * @throws RuntimeException or Error if any task did so.
590 >     * @throws NullPointerException if tasks or any element are null
591 >     * @throws RuntimeException or Error if any task did so
592       */
593      public static void invokeAll(Collection<? extends ForkJoinTask<?>> tasks) {
594          if (!(tasks instanceof List)) {
# Line 623 | Line 632 | public abstract class ForkJoinTask<V> im
632      /**
633       * Returns true if the computation performed by this task has
634       * completed (or has been cancelled).
635 +     *
636       * @return true if this computation has completed
637       */
638      public final boolean isDone() {
# Line 631 | Line 641 | public abstract class ForkJoinTask<V> im
641  
642      /**
643       * Returns true if this task was cancelled.
644 +     *
645       * @return true if this task was cancelled
646       */
647      public final boolean isCancelled() {
# Line 670 | Line 681 | public abstract class ForkJoinTask<V> im
681      }
682  
683      /**
684 <     * Returns true if this task threw an exception or was cancelled
684 >     * Returns true if this task threw an exception or was cancelled.
685 >     *
686       * @return true if this task threw an exception or was cancelled
687       */
688      public final boolean isCompletedAbnormally() {
# Line 681 | Line 693 | public abstract class ForkJoinTask<V> im
693       * Returns the exception thrown by the base computation, or a
694       * CancellationException if cancelled, or null if none or if the
695       * method has not yet completed.
696 +     *
697       * @return the exception, or null if none
698       */
699      public final Throwable getException() {
# Line 722 | Line 735 | public abstract class ForkJoinTask<V> im
735       * overridable, but overridden versions must invoke {@code super}
736       * implementation to maintain guarantees.
737       *
738 <     * @param value the result value for this task.
738 >     * @param value the result value for this task
739       */
740      public void complete(V value) {
741          try {
# Line 759 | Line 772 | public abstract class ForkJoinTask<V> im
772       * tasks). This method may be invoked only from within
773       * ForkJoinTask computations. Attempts to invoke in other contexts
774       * result in exceptions or errors possibly including ClassCastException.
775 +     *
776       * @return the computed result
777       */
778      public final V helpJoin() {
# Line 839 | Line 853 | public abstract class ForkJoinTask<V> im
853      /**
854       * Returns the pool hosting the current task execution, or null
855       * if this task is executing outside of any pool.
856 <     * @return the pool, or null if none.
856 >     *
857 >     * @return the pool, or null if none
858       */
859      public static ForkJoinPool getPool() {
860          Thread t = Thread.currentThread();
# Line 856 | Line 871 | public abstract class ForkJoinTask<V> im
871       * were not, stolen. This method may be invoked only from within
872       * ForkJoinTask computations. Attempts to invoke in other contexts
873       * result in exceptions or errors possibly including ClassCastException.
874 +     *
875       * @return true if unforked
876       */
877      public boolean tryUnfork() {
# Line 867 | Line 883 | public abstract class ForkJoinTask<V> im
883       * forked by the current worker thread but not yet executed. This
884       * value may be useful for heuristic decisions about whether to
885       * fork other tasks.
886 +     *
887       * @return the number of tasks
888       */
889      public static int getQueuedTaskCount() {
# Line 875 | Line 892 | public abstract class ForkJoinTask<V> im
892      }
893  
894      /**
895 <     * Returns a estimate of how many more locally queued tasks are
895 >     * Returns an estimate of how many more locally queued tasks are
896       * held by the current worker thread than there are other worker
897       * threads that might steal them.  This value may be useful for
898       * heuristic decisions about whether to fork other tasks. In many
# Line 883 | Line 900 | public abstract class ForkJoinTask<V> im
900       * aim to maintain a small constant surplus (for example, 3) of
901       * tasks, and to process computations locally if this threshold is
902       * exceeded.
903 +     *
904       * @return the surplus number of tasks, which may be negative
905       */
906      public static int getSurplusQueuedTaskCount() {
# Line 899 | Line 917 | public abstract class ForkJoinTask<V> im
917       * aid debugging, as well as to support extensions. Its use in any
918       * other context is discouraged.
919       *
920 <     * @return the result, or null if not completed.
920 >     * @return the result, or null if not completed
921       */
922      public abstract V getRawResult();
923  
# Line 920 | Line 938 | public abstract class ForkJoinTask<V> im
938       * asynchronous actions that require explicit invocations of
939       * {@code complete} to become joinable. It may throw exceptions
940       * to indicate abnormal exit.
941 +     *
942       * @return true if completed normally
943       * @throws Error or RuntimeException if encountered during computation
944       */
# Line 984 | Line 1003 | public abstract class ForkJoinTask<V> im
1003       * Save the state to a stream.
1004       *
1005       * @serialData the current run status and the exception thrown
1006 <     * during execution, or null if none.
1006 >     * during execution, or null if none
1007       * @param s the stream
1008       */
1009      private void writeObject(java.io.ObjectOutputStream s)
# Line 995 | Line 1014 | public abstract class ForkJoinTask<V> im
1014  
1015      /**
1016       * Reconstitute the instance from a stream.
1017 +     *
1018       * @param s the stream
1019       */
1020      private void readObject(java.io.ObjectInputStream s)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines