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