I have a SwingWorker
which calls some code that does not check for thread interruption. After the call to worker.cancel(true)
, the worker.ge
Inspired by the solution by Paul Blessing I improved it a little to become a class, you can subclass to get the desired funcitonality:
class AwaitingWorker extends SwingWorker {
private final CountDownLatch actuallyFinishedLatch = new CountDownLatch(1);
/**
* Override this to do something useful
*/
protected abstract void performOperation();
@Override
protected final T doInBackground() throws Exception {
try {
return performOperation();
} finally {
actuallyFinishedLatch.countDown();
}
}
public void awaitActualCompletion() throws InterruptedException {
actuallyFinishedLatch.await();
}
}