sclass RestartableCountdown { java.util.Timer timer; // stops the countdown and restarts it synchronized void start(long delayMS, O action) { stop(); timer = doLater_daemon(delayMS, action); } void start(double delaySeconds, O action) { start(toMS(delaySeconds), action); } synchronized void stop() { cancelTimer(timer); timer = null; } }