From 0f34a56a3547ee6129c040351f3994b626c3647a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 23 Sep 2010 14:03:18 +0200 Subject: Fix: In case of a sync notifyObject, the whole action must be synchronized/locked. --- src/java/com/jogamp/common/util/RunnableTask.java | 45 +++++++++++++++++------ 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'src/java') diff --git a/src/java/com/jogamp/common/util/RunnableTask.java b/src/java/com/jogamp/common/util/RunnableTask.java index 15da993..f885f46 100644 --- a/src/java/com/jogamp/common/util/RunnableTask.java +++ b/src/java/com/jogamp/common/util/RunnableTask.java @@ -59,25 +59,48 @@ public class RunnableTask implements Runnable { public void run() { ts1 = System.currentTimeMillis(); - try { - runnable.run(); - } catch (Throwable t) { - runnableException = t; - if(!catchExceptions) { - throw new RuntimeException(runnableException); + if(null == notifyObject) { + try { + runnable.run(); + } catch (Throwable t) { + runnableException = t; + if(catchExceptions) { + runnableException.printStackTrace(); + } else { + throw new RuntimeException(runnableException); + } + } finally { + ts2 = System.currentTimeMillis(); } - } finally { - ts2 = System.currentTimeMillis(); - } - if(null != notifyObject) { + } else { synchronized (notifyObject) { - notifyObject.notifyAll(); + try { + runnable.run(); + } catch (Throwable t) { + runnableException = t; + if(catchExceptions) { + runnableException.printStackTrace(); + } else { + throw new RuntimeException(runnableException); + } + } finally { + ts2 = System.currentTimeMillis(); + notifyObject.notifyAll(); + } } } } + /** + * @return True if executed, otherwise false; + */ public boolean isExecuted() { return 0 != ts2 ; } + + /** + * @return A Throwable thrown while execution if any + */ public Throwable getThrowable() { return runnableException; } + public long getTimestampCreate() { return ts0; } public long getTimestampBeforeExec() { return ts1; } public long getTimestampAfterExec() { return ts2; } -- cgit v1.2.3