mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8186265: Make toString() methods of "task" objects more useful
Reviewed-by: martin, psandoz, rriggs, dholmes, darcy
This commit is contained in:
parent
2ea646cc20
commit
229cce5f44
10 changed files with 240 additions and 23 deletions
|
@ -2490,13 +2490,13 @@ public class CompletableFuture<T> implements Future<T>, CompletionStage<T> {
|
|||
for (Completion p = stack; p != null; p = p.next)
|
||||
++count;
|
||||
return super.toString() +
|
||||
((r == null) ?
|
||||
((count == 0) ?
|
||||
"[Not completed]" :
|
||||
"[Not completed, " + count + " dependents]") :
|
||||
(((r instanceof AltResult) && ((AltResult)r).ex != null) ?
|
||||
"[Completed exceptionally]" :
|
||||
"[Completed normally]"));
|
||||
((r == null)
|
||||
? ((count == 0)
|
||||
? "[Not completed]"
|
||||
: "[Not completed, " + count + " dependents]")
|
||||
: (((r instanceof AltResult) && ((AltResult)r).ex != null)
|
||||
? "[Completed exceptionally: " + ((AltResult)r).ex + "]"
|
||||
: "[Completed normally]"));
|
||||
}
|
||||
|
||||
// jdk9 additions
|
||||
|
|
|
@ -514,6 +514,9 @@ public class Executors {
|
|||
task.run();
|
||||
return result;
|
||||
}
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + task + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,6 +543,10 @@ public class Executors {
|
|||
throw e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + task + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -592,6 +599,10 @@ public class Executors {
|
|||
throw e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + task + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1375,6 +1375,9 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
|
|||
public final void setRawResult(T v) { result = v; }
|
||||
public final boolean exec() { runnable.run(); return true; }
|
||||
public final void run() { invoke(); }
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + runnable + "]";
|
||||
}
|
||||
private static final long serialVersionUID = 5232453952276885070L;
|
||||
}
|
||||
|
||||
|
@ -1392,6 +1395,9 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
|
|||
public final void setRawResult(Void v) { }
|
||||
public final boolean exec() { runnable.run(); return true; }
|
||||
public final void run() { invoke(); }
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + runnable + "]";
|
||||
}
|
||||
private static final long serialVersionUID = 5232453952276885070L;
|
||||
}
|
||||
|
||||
|
@ -1437,6 +1443,9 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
|
|||
}
|
||||
}
|
||||
public final void run() { invoke(); }
|
||||
public String toString() {
|
||||
return super.toString() + "[Wrapped task = " + callable + "]";
|
||||
}
|
||||
private static final long serialVersionUID = 2838392045355241008L;
|
||||
}
|
||||
|
||||
|
|
|
@ -480,6 +480,41 @@ public class FutureTask<V> implements RunnableFuture<V> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
// VarHandle mechanics
|
||||
private static final VarHandle STATE;
|
||||
private static final VarHandle RUNNER;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue