< prev index next >

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

Print this page
@@ -203,10 +203,52 @@
              (s = awaitDone(true, unit.toNanos(timeout))) <= COMPLETING)
              throw new TimeoutException();
          return report(s);
      }
  
+     @Override
+     public V completedResultNow() {
+         if (state == NORMAL) {
+             @SuppressWarnings("unchecked")
+             V result = (V) outcome;
+             return result;
+         } else {
+             throw new IllegalStateException();
+         }
+     }
+ 
+     @Override
+     public Throwable completedExceptionNow() {
+         switch (state) {
+             case EXCEPTIONAL:
+                 Object x = outcome;
+                 return (Throwable) x;
+             case CANCELLED:
+             case INTERRUPTING:
+             case INTERRUPTED:
+                 return new CancellationException();
+             default:
+                 throw new IllegalStateException();
+         }
+     }
+ 
+     @Override
+     public State state() {
+         switch (state) {
+             case NORMAL:
+                 return State.SUCCESS;
+             case EXCEPTIONAL:
+                 return State.FAILED;
+             case CANCELLED:
+             case INTERRUPTING:
+             case INTERRUPTED:
+                 return State.CANCELLED;
+             default:
+                 return State.RUNNING;
+         }
+     }
+ 
      /**
       * Protected method invoked when this task transitions to state
       * {@code isDone} (whether normally or via cancellation). The
       * default implementation does nothing.  Subclasses may override
       * this method to invoke completion callbacks or perform
< prev index next >