454 |
|
} |
455 |
|
} |
456 |
|
|
457 |
+ |
/** |
458 |
+ |
* Returns a string representation of this FutureTask. |
459 |
+ |
* |
460 |
+ |
* @implSpec |
461 |
+ |
* The default implementation returns a string identifying this |
462 |
+ |
* FutureTask, as well as its completion state. The state, in |
463 |
+ |
* brackets, contains one of the strings {@code "Completed Normally"}, |
464 |
+ |
* {@code "Completed Exceptionally"}, {@code "Cancelled"}, or {@code |
465 |
+ |
* "Not completed"}. |
466 |
+ |
* |
467 |
+ |
* @return a string representation of this FutureTask |
468 |
+ |
*/ |
469 |
+ |
public String toString() { |
470 |
+ |
final String status; |
471 |
+ |
switch (state) { |
472 |
+ |
case NORMAL: |
473 |
+ |
status = "[Completed normally]"; |
474 |
+ |
break; |
475 |
+ |
case EXCEPTIONAL: |
476 |
+ |
status = "[Completed exceptionally: " + outcome + "]"; |
477 |
+ |
break; |
478 |
+ |
case CANCELLED: |
479 |
+ |
case INTERRUPTING: |
480 |
+ |
case INTERRUPTED: |
481 |
+ |
status = "[Cancelled]"; |
482 |
+ |
break; |
483 |
+ |
default: |
484 |
+ |
final Callable<?> callable = this.callable; |
485 |
+ |
status = (callable == null) |
486 |
+ |
? "[Not completed]" |
487 |
+ |
: "[Not completed, task = " + callable + "]"; |
488 |
+ |
} |
489 |
+ |
return super.toString() + status; |
490 |
+ |
} |
491 |
+ |
|
492 |
|
// Unsafe mechanics |
493 |
|
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
494 |
|
private static final long STATE; |