private void tick() throws Exception { if (active.getAndSet(true)) return; on(this); activeSchedule = scheduler.after(duration * 1000L); activeSchedule.then( (p) -> { off(State.this); active.set(false); return null; }); }
public void close() { if (closed.getAndSet(true)) { if (waitSchedule != null) try { waitSchedule.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (activeSchedule != null) activeSchedule.cancel(); } }