summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/TaskBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/common/util/TaskBase.java')
-rw-r--r--src/java/com/jogamp/common/util/TaskBase.java43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/java/com/jogamp/common/util/TaskBase.java b/src/java/com/jogamp/common/util/TaskBase.java
index 59b86c3..64a8313 100644
--- a/src/java/com/jogamp/common/util/TaskBase.java
+++ b/src/java/com/jogamp/common/util/TaskBase.java
@@ -54,17 +54,29 @@ public abstract class TaskBase implements Runnable {
protected Throwable runnableException;
protected long tCreated, tStarted;
protected volatile long tExecuted;
+ protected volatile boolean isExecuted;
protected volatile boolean isFlushed;
+ protected volatile Thread execThread;
+ /**
+ * @param syncObject The synchronization object if caller wait until <code>runnable</code> execution is completed,
+ * or <code>null</code> if waiting is not desired.
+ * @param catchExceptions Influence an occurring exception during <code>runnable</code> execution.
+ * If <code>true</code>, the exception is silenced and can be retrieved via {@link #getThrowable()},
+ * otherwise the exception is thrown.
+ * @param exceptionOut If not <code>null</code>, exceptions are written to this {@link PrintStream}.
+ */
protected TaskBase(final Object syncObject, final boolean catchExceptions, final PrintStream exceptionOut) {
this.syncObject = syncObject;
this.catchExceptions = catchExceptions;
this.exceptionOut = exceptionOut;
this.sourceStack = TRACE_SOURCE ? new Throwable("Creation @") : null;
- tCreated = System.currentTimeMillis();
- tStarted = 0;
- tExecuted = 0;
- isFlushed = false;
+ this.tCreated = System.currentTimeMillis();
+ this.tStarted = 0;
+ this.tExecuted = 0;
+ this.isExecuted = false;
+ this.isFlushed = false;
+ this.execThread = null;
}
protected final String getExceptionOutIntro() {
@@ -77,6 +89,14 @@ public abstract class TaskBase implements Runnable {
}
/**
+ * Returns the execution thread or {@code null} if not yet {@link #run()}.
+ * @since 2.3.2
+ */
+ public final Thread getExecutionThread() {
+ return execThread;
+ }
+
+ /**
* Return the synchronization object if any.
* @see #RunnableTask(Runnable, Object, boolean)
*/
@@ -126,12 +146,12 @@ public abstract class TaskBase implements Runnable {
/**
* @return !{@link #isExecuted()} && !{@link #isFlushed()}
*/
- public final boolean isInQueue() { return 0 != tExecuted && !isFlushed; }
+ public final boolean isInQueue() { return !isExecuted && !isFlushed; }
/**
* @return True if executed, otherwise false;
*/
- public final boolean isExecuted() { return 0 != tExecuted ; }
+ public final boolean isExecuted() { return isExecuted; }
/**
* @return True if flushed, otherwise false;
@@ -159,7 +179,16 @@ public abstract class TaskBase implements Runnable {
@Override
public String toString() {
- return "RunnableTask[executed "+isExecuted()+", tTotal "+getDurationTotal()+" ms, tExec "+getDurationInExec()+" ms, tQueue "+getDurationInQueue()+" ms, attachment "+attachment+", throwable "+getThrowable()+"]";
+ final String etn;
+ final String eth;
+ if( null != execThread ) {
+ etn = execThread.getName();
+ eth = "0x"+Integer.toHexString(execThread.hashCode());
+ } else {
+ etn = "n/a";
+ eth = "n/a";
+ }
+ return "RunnableTask[enqueued "+isInQueue()+"[executed "+isExecuted()+", flushed "+isFlushed()+", thread["+eth+", "+etn+"]], tTotal "+getDurationTotal()+" ms, tExec "+getDurationInExec()+" ms, tQueue "+getDurationInQueue()+" ms, attachment "+attachment+", throwable "+getThrowable()+"]";
}
}