diff options
author | Sven Gothel <[email protected]> | 2015-09-12 17:29:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-09-12 17:29:31 +0200 |
commit | 2b97ed6d238a0db1e2cf7bdf15349e90eaaa8dfc (patch) | |
tree | af8429652c07fae310cd2b85921667126019904f /src/java/com/jogamp/common/util/TaskBase.java | |
parent | 47495cd2a228534578731346c8baf2b190bcd241 (diff) |
Bug 1213 (related): Fix TaskBase, RunnableTask and FunctionTask implementation and semantics
- TaskBase
- requires 'volatile boolean isExecuted' for atomic query of same semantics
- fix isInQueue(): condition was reverse in regars to 'isExecuted'
- expose 'Thread getExecutionThread()' as learned within run() method.
- RunnableTask
- deprecate: 'static invoke(final boolean waitUntilDone, final Runnable runnable)',
since it's nonsense, use runnable.run() instead.
- 'static RunnableTask invokeOnNewThread(..)'
- uses InterruptSource.Thread
- Persistent-Wait
- Cancelable using InterruptedRuntimeException
- FunctionTask
- deprecate 'static <U,V> U invoke(final boolean waitUntilDone, final Function<U,V> func, final V... args)',
since it's nonsense, use func.eval(args) instead.
- 'static FunctionTask<U,V> invokeOnNewThread(..)'
- uses InterruptSource.Thread
- Persistent-Wait
- Cancelable using InterruptedRuntimeException
Diffstat (limited to 'src/java/com/jogamp/common/util/TaskBase.java')
-rw-r--r-- | src/java/com/jogamp/common/util/TaskBase.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/java/com/jogamp/common/util/TaskBase.java b/src/java/com/jogamp/common/util/TaskBase.java index 59b86c3..518aeba 100644 --- a/src/java/com/jogamp/common/util/TaskBase.java +++ b/src/java/com/jogamp/common/util/TaskBase.java @@ -54,7 +54,9 @@ 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; protected TaskBase(final Object syncObject, final boolean catchExceptions, final PrintStream exceptionOut) { this.syncObject = syncObject; @@ -64,7 +66,9 @@ public abstract class TaskBase implements Runnable { tCreated = System.currentTimeMillis(); tStarted = 0; tExecuted = 0; + isExecuted = false; isFlushed = false; + execThread = null; } protected final String getExceptionOutIntro() { @@ -76,6 +80,11 @@ public abstract class TaskBase implements Runnable { } } + /** Returns the execution thread or {@code null} if not yet {@link #run()}. */ + public final Thread getExecutionThread() { + return execThread; + } + /** * Return the synchronization object if any. * @see #RunnableTask(Runnable, Object, boolean) @@ -126,12 +135,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 +168,7 @@ 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()+"]"; + return "RunnableTask[enqueued "+isInQueue()+"[executed "+isExecuted()+", flushed "+isFlushed()+"], tTotal "+getDurationTotal()+" ms, tExec "+getDurationInExec()+" ms, tQueue "+getDurationInQueue()+" ms, attachment "+attachment+", throwable "+getThrowable()+"]"; } } |