@Test public void testScheduledTasks() throws Exception { TestRunnable task = new TestRunnable(0); ScheduledFuture<?> f = e.schedule(task, 1500, TimeUnit.MILLISECONDS); f.sync(); assertThat(task.ran.get(), is(true)); Thread thread = e.thread; assertThat(thread, is(not(nullValue()))); assertThat(thread.isAlive(), is(true)); Thread.sleep(1500); assertThat(thread.isAlive(), is(false)); assertThat(e.thread, sameInstance(thread)); }
@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { if (command == null) { throw new NullPointerException("command"); } if (unit == null) { throw new NullPointerException("unit"); } if (delay < 0) { throw new IllegalArgumentException( String.format("delay: %d (expected: >= 0)", delay)); } return schedule(new ScheduledFutureTask<Void>( this, delayedTaskQueue, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay)))); }
GlobalEventExecutor extends AbstractEventExecutor { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { if (command == null) { throw new NullPointerException("command"); } if (unit == null) { throw new NullPointerException("unit"); } if (delay < 0) { throw new IllegalArgumentException( String.format("delay: %d (expected: >= 0)", delay)); } return schedule(new ScheduledFutureTask<Void>( this, delayedTaskQueue, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay)))); } }
GlobalEventExecutor extends AbstractEventExecutor { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { if (command == null) { throw new NullPointerException("command"); } if (unit == null) { throw new NullPointerException("unit"); } if (delay < 0) { throw new IllegalArgumentException( String.format("delay: %d (expected: >= 0)", delay)); } return schedule(new ScheduledFutureTask<Void>( this, delayedTaskQueue, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay)))); } private  GlobalEventExecutor(); }
GlobalEventExecutor extends AbstractEventExecutor { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { if (command == null) { throw new NullPointerException("command"); } if (unit == null) { throw new NullPointerException("unit"); } if (delay < 0) { throw new IllegalArgumentException( String.format("delay: %d (expected: >= 0)", delay)); } return schedule(new ScheduledFutureTask<Void>( this, delayedTaskQueue, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay)))); } private  GlobalEventExecutor(); @Override EventExecutorGroup parent(); int pendingTasks(); @Override boolean inEventLoop(Thread thread); @Override Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit); @Override Future<?> terminationFuture(); @Override @Deprecated void shutdown(); @Override boolean isShuttingDown(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override void execute(Runnable task); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit); }
GlobalEventExecutor extends AbstractEventExecutor { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { if (command == null) { throw new NullPointerException("command"); } if (unit == null) { throw new NullPointerException("unit"); } if (delay < 0) { throw new IllegalArgumentException( String.format("delay: %d (expected: >= 0)", delay)); } return schedule(new ScheduledFutureTask<Void>( this, delayedTaskQueue, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay)))); } private  GlobalEventExecutor(); @Override EventExecutorGroup parent(); int pendingTasks(); @Override boolean inEventLoop(Thread thread); @Override Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit); @Override Future<?> terminationFuture(); @Override @Deprecated void shutdown(); @Override boolean isShuttingDown(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override void execute(Runnable task); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit); static final GlobalEventExecutor INSTANCE; }