synchronized void stop() { if (isRunning()) { ticker.cancel(true); // may interrupt if running ticker = null; } // let any threads waiting on the clock fall through synchronized (ticks) { // one should be sufficient but this is to be safe for (int i = 0; i < 5; i++) { ticks.notifyAll(); try { Thread.sleep(10); } catch (InterruptedException ignored) { } } } }
private void incrementTicks() { synchronized (ticks) { ticks.increment(); ticks.notifyAll(); } }