35
35
public class RunnableTask implements Runnable {
37
final Object notifyObject;
37
final Object syncObject;
38
38
boolean catchExceptions;
41
41
Throwable runnableException;
42
42
long ts0, ts1, ts2;
45
* Create a RunnableTask object w/o synchronization,
46
* ie. not suitable for <code>invokeAndWait()</code>.
48
* @param runnable the user action
44
50
public RunnableTask(Runnable runnable) {
45
51
this(runnable, null, false);
48
public RunnableTask(Runnable runnable, Object notifyObject) {
49
this(runnable, notifyObject, false);
55
* Create a RunnableTask object w/ synchronization,
56
* ie. suitable for <code>invokeAndWait()</code>.
58
* @param runnable the user action
59
* @param syncObject the synchronization object the caller shall wait for in case of <code>invokeAndWait()</code>
61
public RunnableTask(Runnable runnable, Object syncObject) {
62
this(runnable, syncObject, false);
52
public RunnableTask(Runnable runnable, Object notifyObject, boolean catchExceptions) {
66
* Create a RunnableTask object w/ synchronization,
67
* ie. suitable for <code>invokeAndWait()</code>.
69
* @param runnable the user action
70
* @param syncObject the synchronization object the caller shall wait for in case of <code>invokeAndWai()t</code>
71
* @param catchExceptions if true, exception during <code>runnable</code> execution are catched, otherwise not.
72
* Use {@link #getThrowable()} to determine whether an exception has been catched.
74
public RunnableTask(Runnable runnable, Object syncObject, boolean catchExceptions) {
53
75
this.runnable = runnable ;
54
this.notifyObject = notifyObject ;
76
this.syncObject = syncObject ;
55
77
this.catchExceptions = catchExceptions ;
56
78
ts0 = System.currentTimeMillis();
83
/** Return the user action */
61
84
public Runnable getRunnable() {
89
* Return the synchronization object if any.
90
* @see #RunnableTask(Runnable, Object, boolean)
92
public Object getSyncObject() {
66
97
* Attach a custom object to this task.
67
98
* Useful to piggybag further information, ie tag a task final.
110
145
public boolean isExecuted() { return 0 != ts2 ; }
113
* @return A Throwable thrown while execution if any
148
* @return True if invoking thread waits until done,
149
* ie a <code>notifyObject</code> was passed, otherwise false;
151
public boolean hasWaiter() { return null != syncObject; }
154
* @return A thrown exception while execution of the user action, if any and if catched
155
* @see #RunnableTask(Runnable, Object, boolean)
115
157
public Throwable getThrowable() { return runnableException; }