diff options
author | Sven Gothel <[email protected]> | 2010-09-23 14:03:18 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-09-23 14:03:18 +0200 |
commit | 0f34a56a3547ee6129c040351f3994b626c3647a (patch) | |
tree | cf532f01dd670adde49676c0ee3f11ae2cd08b57 | |
parent | a61c650db83c625521b7c1145cf6614bb097f6a3 (diff) |
Fix: In case of a sync notifyObject, the whole action must be synchronized/locked.
-rw-r--r-- | src/java/com/jogamp/common/util/RunnableTask.java | 45 |
1 files changed, 34 insertions, 11 deletions
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; } |