private synchronized void update() { int newValue = value.get() - 1; if (newValue <= 0) { task.cancel(); task = null; clear(); return; } value.set(newValue); }
/* * Sync sets up the timer if we previously set the end. */ public synchronized void sync(long time) { if (end == 0) // no roundtime or it's already setup return; if (end > time) value.set((int) (end - time)); else value.set(0); // Set end to 0 to signify that we setup the timer end = 0; if (task != null) task.cancel(); task = new WarlockTimerTask(); timer.scheduleAtFixedRate(task, 1000, 1000); }