public class CachedThreadPoolScheduler extends java.lang.Object implements Scheduler
Executors.newCachedThreadPool()) as its backing thread pool.
Delayed executions are performed via the TimeUnit.sleep() methods on the pool thread (consuming resources).
To stop a repeating schedule, throw a CancellationException.| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.ExecutorService |
pool
The thread pool.
|
| Constructor and Description |
|---|
CachedThreadPoolScheduler()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.io.Closeable |
schedule(java.lang.Runnable run)
Schedule for ASAP execution.
|
java.io.Closeable |
schedule(java.lang.Runnable run,
long initialDelay,
long betweenDelay,
java.util.concurrent.TimeUnit unit)
Schedule a repeated execution of the given task with
the given initialDelay (in nanoseconds) and betweenDelay
(in nanoseconds).
|
java.io.Closeable |
schedule(java.lang.Runnable run,
long delay,
java.util.concurrent.TimeUnit unit)
Schedule a single execution of the runnable task
with the given delay of nanoseconds.
|
public CachedThreadPoolScheduler()
@Nonnull
public java.io.Closeable schedule(@Nonnull
java.lang.Runnable run)
Scheduler@Nonnull
public java.io.Closeable schedule(@Nonnull
java.lang.Runnable run,
long delay,
@Nonnull
java.util.concurrent.TimeUnit unit)
Scheduler@Nonnull
public java.io.Closeable schedule(@Nonnull
java.lang.Runnable run,
long initialDelay,
long betweenDelay,
@Nonnull
java.util.concurrent.TimeUnit unit)
SchedulerExecutorService.scheduleAtFixedRate()).
Note: Implementations might not have the capability to
schedule nanosecond resolution.