< prev index next >

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

Print this page
@@ -896,10 +896,44 @@
       */
      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 completedResultNow() {
+         if ((status & (DONE | ABNORMAL)) == DONE) {
+             return getRawResult();
+         } else {
+             throw new IllegalStateException();
+         }
+     }
+ 
+     @Override
+     public Throwable completedExceptionNow() {
+         Throwable ex = getException(status);
+         if (ex != null) {
+             return ex;
+         } 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.
       *
< prev index next >