diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/jogamp/common/util/FunctionTask.java | 12 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/RunnableTask.java | 14 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/TaskBase.java | 24 |
3 files changed, 39 insertions, 11 deletions
diff --git a/src/java/com/jogamp/common/util/FunctionTask.java b/src/java/com/jogamp/common/util/FunctionTask.java index 8238aff..a131838 100644 --- a/src/java/com/jogamp/common/util/FunctionTask.java +++ b/src/java/com/jogamp/common/util/FunctionTask.java @@ -127,35 +127,41 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> { final A[] args = this.args; this.args = null; this.result = null; + runnableException = null; tStarted = System.currentTimeMillis(); if(null == syncObject) { try { this.result = runnable.eval(args); + tExecuted = System.currentTimeMillis(); } catch (Throwable t) { + tExecuted = System.currentTimeMillis(); runnableException = t; if(null != exceptionOut) { + exceptionOut.println("FunctionTask.run(): "+getExceptionOutIntro()+" exception occured on thread "+Thread.currentThread().getName()+": "+toString()); + printSourceTrace(); t.printStackTrace(exceptionOut); } if(!catchExceptions) { throw new RuntimeException(runnableException); } - } finally { - tExecuted = System.currentTimeMillis(); } } else { synchronized (syncObject) { try { this.result = runnable.eval(args); + tExecuted = System.currentTimeMillis(); } catch (Throwable t) { + tExecuted = System.currentTimeMillis(); runnableException = t; if(null != exceptionOut) { + exceptionOut.println("FunctionTask.run(): "+getExceptionOutIntro()+" exception occured on thread "+Thread.currentThread().getName()+": "+toString()); + printSourceTrace(); t.printStackTrace(exceptionOut); } if(!catchExceptions) { throw new RuntimeException(runnableException); } } finally { - tExecuted = System.currentTimeMillis(); syncObject.notifyAll(); } } diff --git a/src/java/com/jogamp/common/util/RunnableTask.java b/src/java/com/jogamp/common/util/RunnableTask.java index ee484e1..ce4688d 100644 --- a/src/java/com/jogamp/common/util/RunnableTask.java +++ b/src/java/com/jogamp/common/util/RunnableTask.java @@ -88,35 +88,41 @@ public class RunnableTask extends TaskBase { @Override public final void run() { + runnableException = null; tStarted = System.currentTimeMillis(); if(null == syncObject) { try { runnable.run(); + tExecuted = System.currentTimeMillis(); } catch (Throwable t) { + tExecuted = System.currentTimeMillis(); runnableException = t; if(null != exceptionOut) { - t.printStackTrace(exceptionOut); + exceptionOut.println("RunnableTask.run(): "+getExceptionOutIntro()+" exception occured on thread "+Thread.currentThread().getName()+": "+toString()); + printSourceTrace(); + runnableException.printStackTrace(exceptionOut); } if(!catchExceptions) { throw new RuntimeException(runnableException); } - } finally { - tExecuted = System.currentTimeMillis(); } } else { synchronized (syncObject) { try { runnable.run(); + tExecuted = System.currentTimeMillis(); } catch (Throwable t) { + tExecuted = System.currentTimeMillis(); runnableException = t; if(null != exceptionOut) { + exceptionOut.println("RunnableTask.run(): "+getExceptionOutIntro()+" exception occured on thread "+Thread.currentThread().getName()+": "+toString()); + printSourceTrace(); t.printStackTrace(exceptionOut); } if(!catchExceptions) { throw new RuntimeException(runnableException); } } finally { - tExecuted = System.currentTimeMillis(); syncObject.notifyAll(); } } diff --git a/src/java/com/jogamp/common/util/TaskBase.java b/src/java/com/jogamp/common/util/TaskBase.java index 266a5b7..9fd7c0d 100644 --- a/src/java/com/jogamp/common/util/TaskBase.java +++ b/src/java/com/jogamp/common/util/TaskBase.java @@ -30,14 +30,20 @@ package com.jogamp.common.util; import java.io.PrintStream; +import jogamp.common.Debug; + /** * Helper class to provide a Runnable queue implementation with a Runnable wrapper * which notifies after execution for the <code>invokeAndWait()</code> semantics. */ public abstract class TaskBase implements Runnable { + /** Enable via the property <code>jogamp.debug.TaskBase.TraceSource</code> */ + private static final boolean TRACE_SOURCE = Debug.isPropertyDefined("jogamp.debug.TaskBase.TraceSource", true); + protected final Object syncObject; protected final boolean catchExceptions; - protected final PrintStream exceptionOut; + protected final PrintStream exceptionOut; + protected final Throwable sourceStack; protected Object attachment; protected Throwable runnableException; @@ -49,11 +55,21 @@ public abstract class TaskBase implements Runnable { 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; } + + protected final String getExceptionOutIntro() { + return catchExceptions ? "A catched" : "An uncatched"; + } + protected final void printSourceTrace() { + if( null != sourceStack && null != exceptionOut ) { + sourceStack.printStackTrace(exceptionOut); + } + } /** * Return the synchronization object if any. @@ -130,12 +146,12 @@ public abstract class TaskBase implements Runnable { public final long getTimestampBeforeExec() { return tStarted; } public final long getTimestampAfterExec() { return tExecuted; } public final long getDurationInQueue() { return tStarted - tCreated; } - public final long getDurationInExec() { return tExecuted - tStarted; } - public final long getDurationTotal() { return tExecuted - tCreated; } + public final long getDurationInExec() { return 0 < tExecuted ? tExecuted - tStarted : 0; } + public final long getDurationTotal() { return 0 < tExecuted ? tExecuted - tCreated : tStarted - tCreated; } @Override public String toString() { - return "RunnableTask[executed "+isExecuted()+", t2-t0 "+getDurationTotal()+", t2-t1 "+getDurationInExec()+", t1-t0 "+getDurationInQueue()+", throwable "+getThrowable()+", Attachment "+attachment+"]"; + return "RunnableTask[executed "+isExecuted()+", tTotal "+getDurationTotal()+" ms, tExec "+getDurationInExec()+" ms, tQueue "+getDurationInQueue()+" ms, attachment "+attachment+", throwable "+getThrowable()+"]"; } } |