< prev index next >

src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java

Print this page
@@ -405,11 +405,11 @@
              if (internal = (pool == p))
                  q = wt.workQueue;
          }
          else {
              internal = false;
-             p = ForkJoinPool.common;
+             p = ForkJoinPool.CommonPool.common;
              if (pool == null)
                  pool = p;
              if (pool == p && p != null)
                  q = p.externalQueue();
          }

@@ -647,11 +647,11 @@
      public final ForkJoinTask<V> fork() {
          Thread t; ForkJoinWorkerThread w;
          if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread)
              (w = (ForkJoinWorkerThread)t).workQueue.push(this, w.pool);
          else
-             ForkJoinPool.common.externalPush(this);
+             ForkJoinPool.CommonPool.common.externalPush(this);
          return this;
      }
  
      /**
       * Returns the result of the computation when it

@@ -896,10 +896,43 @@
       */
      public final boolean isCompletedNormally() {
          return (status & (DONE | ABNORMAL)) == DONE;
      }
  
+     @Override
+     public State state() {
+         int s = status;
+         if (s < 0) {
+             if ((s & (DONE | ABNORMAL)) == DONE)
+                 return State.SUCCESS;
+             if ((s & (ABNORMAL | THROWN)) == (ABNORMAL | THROWN))
+                 return State.FAILED;
+             else
+                 return State.CANCELLED;
+         } else {
+             return State.RUNNING;
+         }
+     }
+ 
+     @Override
+     public V resultNow() {
+         if ((status & (DONE | ABNORMAL)) == DONE) {
+             return getRawResult();
+         } else {
+             throw new IllegalStateException();
+         }
+     }
+ 
+     @Override
+     public Throwable exceptionNow() {
+         if ((status & (ABNORMAL | THROWN)) == (ABNORMAL | THROWN)) {
+             return getThrowableException();
+         } else {
+             throw new IllegalStateException();
+         }
+     }
+ 
      /**
       * Returns the exception thrown by the base computation, or a
       * {@code CancellationException} if cancelled, or {@code null} if
       * none or if the method has not yet completed.
       *

@@ -1068,11 +1101,11 @@
          Thread t; ForkJoinWorkerThread w; ForkJoinPool p;
          if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread &&
              (p = (w = (ForkJoinWorkerThread)t).pool) != null)
              p.helpQuiescePool(w.workQueue, Long.MAX_VALUE, false);
          else
-             ForkJoinPool.common.externalHelpQuiescePool(Long.MAX_VALUE, false);
+             ForkJoinPool.CommonPool.common.externalHelpQuiescePool(Long.MAX_VALUE, false);
      }
  
      /**
       * Resets the internal bookkeeping state of this task, allowing a
       * subsequent {@code fork}. This method allows repeated reuse of
< prev index next >