Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.thread

public Class ScheduledExecutorScheduler

extends AbstractLifeCycle
implements Scheduler, Dumpable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.thread.Scheduler, org.eclipse.jetty.util.component.LifeCycle
Annotations
@ManagedObject
Imports
java.io.IOException, java.util.concurrent.ScheduledExecutorService, .ScheduledFuture, .ScheduledThreadPoolExecutor, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, org.eclipse.jetty.util.StringUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, .Name, org.eclipse.jetty.util.component.AbstractLifeCycle, .Dumpable

Implementation of 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final AtomicInteger
private final boolean
private final String
private volatile ScheduledExecutorService
private volatile Thread
private final ThreadGroup
private final int
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
FAILEDSTARTEDSTARTINGSTOPPEDSTOPPING

Constructor Summary

AccessConstructor and Description
public
public
ScheduledExecutorScheduler(String name, boolean daemon)

public
ScheduledExecutorScheduler(String name, boolean daemon, int threads)

public
ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader)

public
ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader, ThreadGroup threadGroup)

public
ScheduledExecutorScheduler(String
The name of the scheduler threads or null for automatic name
name
,
boolean
True if scheduler threads should be daemon
daemon
,
ClassLoader
The classloader to run the threads with or null to use the current thread context classloader
classLoader
,
ThreadGroup
The threadgroup to use or null for no thread group
threadGroup
,
int
The number of threads to pass to the core ScheduledExecutorService or -1 for a heuristic determined number of threads.
threads
)

public

Method Summary

Modifier and TypeMethod and Description
protected void
doStart()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

protected void
doStop()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

public String
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public String
public int
public boolean
public Scheduler.Task
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
addEventListenergetEventListenersgetStategetStateisFailedisRunningisStartedisStartingisStoppedisStoppingremoveEventListenersetEventListenersstartstoptoString

Field Detail

classloaderback to summary
private final ClassLoader classloader
countback to summary
private final AtomicInteger count
daemonback to summary
private final boolean daemon
nameback to summary
private final String name
schedulerback to summary
private volatile ScheduledExecutorService scheduler
threadback to summary
private volatile Thread thread
threadGroupback to summary
private final ThreadGroup threadGroup
threadsback to summary
private final int threads

Constructor Detail

ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler()
ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(String name, boolean daemon)
ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(String name, boolean daemon, int threads)
ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader)
ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader, ThreadGroup threadGroup)
ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader, ThreadGroup threadGroup, int threads)
Parameters
name:String

The name of the scheduler threads or null for automatic name

daemon:boolean

True if scheduler threads should be daemon

classLoader:ClassLoader

The classloader to run the threads with or null to use the current thread context classloader

threadGroup:ThreadGroup

The threadgroup to use or null for no thread group

threads:int

The number of threads to pass to the core ScheduledExecutorService or -1 for a heuristic determined number of threads.

ScheduledExecutorSchedulerback to summary
public ScheduledExecutorScheduler(ScheduledExecutorService scheduledExecutorService)
Parameters
scheduledExecutorService:ScheduledExecutorService

the core ScheduledExecutorService to be used

Method Detail

doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem starting. Will cause a transition to FAILED state
doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem stopping. Will cause a transition to FAILED state
dumpback to summary
public String dump()

Overrides default org.eclipse.jetty.util.component.Dumpable.dump.

Annotations
@Override
dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
getNameback to summary
public String getName()
Annotations
@ManagedAttribute:The name of the scheduler
getThreadsback to summary
public int getThreads()
Annotations
@ManagedAttribute:The number of scheduler threads
isDaemonback to summary
public boolean isDaemon()
Annotations
@ManagedAttribute:Whether the scheduler uses daemon threads
scheduleback to summary
public Scheduler.Task schedule(Runnable task, long delay, TimeUnit unit)

Implements org.eclipse.jetty.util.thread.Scheduler.schedule.

Annotations
@Override
org.eclipse.jetty.util.thread back to summary

private Class ScheduledExecutorScheduler.ScheduledFutureTask

extends Object
implements Task
Class Inheritance
  • java.lang.Object
  • org.eclipse.jetty.util.thread.ScheduledExecutorScheduler.ScheduledFutureTask
All Implemented Interfaces
org.eclipse.jetty.util.thread.Scheduler.Task

Field Summary

Modifier and TypeField and Description
private final ScheduledFuture<?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

scheduledFutureback to summary
private final ScheduledFuture<?> scheduledFuture

Constructor Detail

ScheduledFutureTaskback to summary
pack-priv ScheduledFutureTask(ScheduledFuture<?> scheduledFuture)

Method Detail

cancelback to summary
public boolean cancel()

Implements org.eclipse.jetty.util.thread.Scheduler.Task.cancel.

Annotations
@Override