--- jsr166/src/jdk8/java/util/concurrent/FutureTask.java 2016/03/26 06:22:50 1.1 +++ jsr166/src/jdk8/java/util/concurrent/FutureTask.java 2017/09/26 03:44:53 1.2 @@ -454,6 +454,41 @@ public class FutureTask implements Ru } } + /** + * Returns a string representation of this FutureTask. + * + * @implSpec + * The default implementation returns a string identifying this + * FutureTask, as well as its completion state. The state, in + * brackets, contains one of the strings {@code "Completed Normally"}, + * {@code "Completed Exceptionally"}, {@code "Cancelled"}, or {@code + * "Not completed"}. + * + * @return a string representation of this FutureTask + */ + public String toString() { + final String status; + switch (state) { + case NORMAL: + status = "[Completed normally]"; + break; + case EXCEPTIONAL: + status = "[Completed exceptionally: " + outcome + "]"; + break; + case CANCELLED: + case INTERRUPTING: + case INTERRUPTED: + status = "[Cancelled]"; + break; + default: + final Callable callable = this.callable; + status = (callable == null) + ? "[Not completed]" + : "[Not completed, task = " + callable + "]"; + } + return super.toString() + status; + } + // Unsafe mechanics private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); private static final long STATE;