final class ControlledStop implements Runnable {
private boolean done = false;
@Override public void run() {
while (!isDone()) {
try {
Thread.currentThread().sleep(1000); } catch(InterruptedException ie) {
Thread.currentThread().interrupt(); }
}
}
public synchronized boolean isDone() {
return done;
}
public synchronized void shutdown() {
done = true;
}
}