blob: 53315b77cb1e3f0d05f21880387c04a770178a62 [file] [log] [blame]
package edu.uci.ics.hyracks.control.cc.jobqueue;
public abstract class SynchronizableRunnable implements Runnable {
private boolean done;
private Exception e;
protected abstract void doRun() throws Exception;
public void init() {
done = false;
e = null;
}
@Override
public final void run() {
try {
doRun();
} catch (Exception e) {
this.e = e;
} finally {
synchronized (this) {
done = true;
notifyAll();
}
}
}
public final synchronized void sync() throws Exception {
while (!done) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (e != null) {
throw e;
}
}
}