PollScheduler { public void stop() { ScheduledExecutorService service = executor.get(); if (service != null && executor.compareAndSet(service, null)) { service.shutdown(); } else { throw new IllegalStateException("scheduler must be started before you stop it"); } } private  PollScheduler(); static PollScheduler getInstance(); void addPoller(PollRunnable task, long delay, TimeUnit timeUnit); void start(); void start(ScheduledExecutorService service); void stop(); boolean isStarted();  }
@Test public void testStop() throws Exception { ScheduledExecutorService s = Executors.newScheduledThreadPool(2); PollScheduler.getInstance().start(s); assertTrue(PollScheduler.getInstance().isStarted()); PollScheduler.getInstance().stop(); assertTrue(!PollScheduler.getInstance().isStarted()); assertTrue(s.isShutdown()); }