HashedWheelTimer implements Timer { @Override public Set<Timeout> stop() { if (Thread.currentThread() == workerThread) { throw new IllegalStateException( HashedWheelTimer.class.getSimpleName() + ".stop() cannot be called from " + TimerTask.class.getSimpleName()); } if (!WORKER_STATE_UPDATER.compareAndSet(this, WORKER_STATE_STARTED, WORKER_STATE_SHUTDOWN)) { if (WORKER_STATE_UPDATER.getAndSet(this, WORKER_STATE_SHUTDOWN) != WORKER_STATE_SHUTDOWN) { INSTANCE_COUNTER.decrementAndGet(); } return Collections.emptySet(); } try { boolean interrupted = false; while (workerThread.isAlive()) { workerThread.interrupt(); try { workerThread.join(100); } catch (InterruptedException ignored) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } } finally { INSTANCE_COUNTER.decrementAndGet(); } return worker.unprocessedTimeouts(); } HashedWheelTimer();  HashedWheelTimer(long tickDuration, TimeUnit unit);  HashedWheelTimer(long tickDuration, TimeUnit unit, int ticksPerWheel);  HashedWheelTimer(ThreadFactory threadFactory);  HashedWheelTimer(
            ThreadFactory threadFactory, long tickDuration, TimeUnit unit);  HashedWheelTimer(
            ThreadFactory threadFactory,
            long tickDuration, TimeUnit unit, int ticksPerWheel);  HashedWheelTimer(
            ThreadFactory threadFactory,
            long tickDuration, TimeUnit unit, int ticksPerWheel,
            long maxPendingTimeouts); void start(); @Override Set<Timeout> stop(); @Override boolean isStop(); @Override Timeout newTimeout(TimerTask task, long delay, TimeUnit unit); long pendingTimeouts(); static final String NAME; }
@Test public void stop() throws InterruptedException { final Timer timer = newTimer(); for (int i = 0; i < 10; i++) { timer.newTimeout(new PrintTask(), 5, TimeUnit.SECONDS); Thread.sleep(100); } timer.stop(); try { timer.newTimeout(new PrintTask(), 5, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); } }