public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler, Dumpable
Scheduler
based on JDK's ScheduledThreadPoolExecutor
.
While use of ScheduledThreadPoolExecutor
creates futures that will not be used,
it has the advantage of allowing to set a property to remove cancelled tasks from its
queue even if the task did not fire, which provides a huge benefit in the performance
of garbage collection in young generation.
Modifier and Type | Class and Description |
---|---|
private static class |
ScheduledExecutorScheduler.ScheduledFutureTask |
AbstractLifeCycle.AbstractLifeCycleListener
Scheduler.Task
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
private java.lang.ClassLoader |
classloader |
private java.util.concurrent.atomic.AtomicInteger |
count |
private boolean |
daemon |
private java.lang.String |
name |
private java.util.concurrent.ScheduledThreadPoolExecutor |
scheduler |
private java.lang.Thread |
thread |
private java.lang.ThreadGroup |
threadGroup |
private int |
threads |
Constructor and Description |
---|
ScheduledExecutorScheduler() |
ScheduledExecutorScheduler(java.lang.String name,
boolean daemon) |
ScheduledExecutorScheduler(java.lang.String name,
boolean daemon,
java.lang.ClassLoader classLoader) |
ScheduledExecutorScheduler(java.lang.String name,
boolean daemon,
java.lang.ClassLoader classLoader,
java.lang.ThreadGroup threadGroup) |
ScheduledExecutorScheduler(java.lang.String name,
boolean daemon,
java.lang.ClassLoader classLoader,
java.lang.ThreadGroup threadGroup,
int threads) |
ScheduledExecutorScheduler(java.lang.String name,
boolean daemon,
int threads) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart() |
protected void |
doStop() |
java.lang.String |
dump() |
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
Scheduler.Task |
schedule(java.lang.Runnable task,
long delay,
java.util.concurrent.TimeUnit unit) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stop
dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, named
private final java.lang.String name
private final boolean daemon
private final java.lang.ClassLoader classloader
private final java.lang.ThreadGroup threadGroup
private final int threads
private final java.util.concurrent.atomic.AtomicInteger count
private volatile java.util.concurrent.ScheduledThreadPoolExecutor scheduler
private volatile java.lang.Thread thread
public ScheduledExecutorScheduler()
public ScheduledExecutorScheduler(java.lang.String name, boolean daemon)
public ScheduledExecutorScheduler(@Name(value="name") java.lang.String name, @Name(value="daemon") boolean daemon, @Name(value="threads") int threads)
public ScheduledExecutorScheduler(java.lang.String name, boolean daemon, java.lang.ClassLoader classLoader)
public ScheduledExecutorScheduler(java.lang.String name, boolean daemon, java.lang.ClassLoader classLoader, java.lang.ThreadGroup threadGroup)
public ScheduledExecutorScheduler(@Name(value="name") java.lang.String name, @Name(value="daemon") boolean daemon, @Name(value="classLoader") java.lang.ClassLoader classLoader, @Name(value="threadGroup") java.lang.ThreadGroup threadGroup, @Name(value="threads") int threads)
name
- The name of the scheduler threads or null for automatic namedaemon
- True if scheduler threads should be daemonclassLoader
- The classloader to run the threads with or null to use the current thread context classloaderthreadGroup
- The threadgroup to use or null for no thread groupthreads
- The number of threads to pass to the the core ScheduledThreadPoolExecutor
or -1 for a
heuristic determined number of threads.protected void doStart() throws java.lang.Exception
doStart
in class AbstractLifeCycle
java.lang.Exception
protected void doStop() throws java.lang.Exception
doStop
in class AbstractLifeCycle
java.lang.Exception
public Scheduler.Task schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Dumpable