public final class GlobalEventExecutor extends AbstractScheduledEventExecutor
EventExecutor
. It starts the thread automatically and stops it when there is no
task pending in the task queue for 1 second. Please note it is not scalable to schedule large number of tasks to
this executor; use a dedicated executor.Modifier and Type | Class and Description |
---|---|
(package private) class |
GlobalEventExecutor.TaskRunner |
Modifier and Type | Field and Description |
---|---|
static GlobalEventExecutor |
INSTANCE |
private static InternalLogger |
logger |
(package private) ScheduledFutureTask<java.lang.Void> |
quietPeriodTask |
private static long |
SCHEDULE_QUIET_PERIOD_INTERVAL |
private java.util.concurrent.atomic.AtomicBoolean |
started |
(package private) java.util.concurrent.BlockingQueue<java.lang.Runnable> |
taskQueue |
private GlobalEventExecutor.TaskRunner |
taskRunner |
private Future<?> |
terminationFuture |
(package private) java.lang.Thread |
thread |
(package private) java.util.concurrent.ThreadFactory |
threadFactory |
scheduledTaskQueue
Modifier | Constructor and Description |
---|---|
private |
GlobalEventExecutor() |
Modifier and Type | Method and Description |
---|---|
private void |
addTask(java.lang.Runnable task)
Add a task to the task queue, or throws a
RejectedExecutionException if this instance was shutdown
before. |
boolean |
awaitInactivity(long timeout,
java.util.concurrent.TimeUnit unit)
Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself.
|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
execute(java.lang.Runnable task) |
private void |
fetchFromScheduledTaskQueue() |
boolean |
inEventLoop(java.lang.Thread thread)
Return
true if the given Thread is executed in the event loop,
false otherwise. |
boolean |
isShutdown() |
boolean |
isShuttingDown()
Returns
true if and only if this executor was started to be
shut down gracefuclly or was shut down. |
boolean |
isTerminated() |
EventExecutorGroup |
parent()
Return the
EventExecutorGroup which is the parent of this EventExecutor , |
int |
pendingTasks()
Return the number of tasks that are pending for processing.
|
void |
shutdown()
Deprecated.
|
Future<?> |
shutdownGracefully(long quietPeriod,
long timeout,
java.util.concurrent.TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down.
|
private void |
startThread() |
(package private) java.lang.Runnable |
takeTask()
Take the next
Runnable from the task queue and so will block if no task is currently present. |
Future<?> |
terminationFuture()
Returns the
Future which is notified when this executor has been terminated. |
cancelScheduledTasks, hasScheduledTasks, nanoTime, nextScheduledTaskNano, peekScheduledTask, pollScheduledTask, pollScheduledTask, removeScheduled, schedule, schedule, schedule, scheduleAtFixedRate, scheduledTaskQueue, scheduleWithFixedDelay
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, shutdownGracefully, shutdownNow, submit, submit, submit
invokeAll, invokeAll, invokeAny, invokeAny
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
private static final InternalLogger logger
private static final long SCHEDULE_QUIET_PERIOD_INTERVAL
public static final GlobalEventExecutor INSTANCE
final java.util.concurrent.BlockingQueue<java.lang.Runnable> taskQueue
final ScheduledFutureTask<java.lang.Void> quietPeriodTask
final java.util.concurrent.ThreadFactory threadFactory
private final GlobalEventExecutor.TaskRunner taskRunner
private final java.util.concurrent.atomic.AtomicBoolean started
volatile java.lang.Thread thread
private final Future<?> terminationFuture
public EventExecutorGroup parent()
EventExecutor
EventExecutorGroup
which is the parent of this EventExecutor
,java.lang.Runnable takeTask()
Runnable
from the task queue and so will block if no task is currently present.null
if the executor thread has been interrupted or waken up.private void fetchFromScheduledTaskQueue()
public int pendingTasks()
private void addTask(java.lang.Runnable task)
RejectedExecutionException
if this instance was shutdown
before.public boolean inEventLoop(java.lang.Thread thread)
EventExecutor
true
if the given Thread
is executed in the event loop,
false
otherwise.public Future<?> shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.TimeUnit unit)
EventExecutorGroup
EventExecutorGroup.isShuttingDown()
starts to return true
, and the executor prepares to shut itself down.
Unlike EventExecutorGroup.shutdown()
, graceful shutdown ensures that no tasks are submitted for 'the quiet period'
(usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period,
it is guaranteed to be accepted and the quiet period will start over.quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown()
regardless if a task was submitted during the quiet periodunit
- the unit of quietPeriod
and timeout
EventExecutorGroup.terminationFuture()
public Future<?> terminationFuture()
EventExecutorGroup
Future
which is notified when this executor has been terminated.@Deprecated public void shutdown()
shutdown
in interface EventExecutorGroup
shutdown
in interface java.util.concurrent.ExecutorService
shutdown
in class AbstractEventExecutor
public boolean isShuttingDown()
EventExecutorGroup
true
if and only if this executor was started to be
shut down gracefuclly or was shut down.public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
public boolean awaitInactivity(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
true
if and only if the worker thread has been terminatedjava.lang.InterruptedException
public void execute(java.lang.Runnable task)
private void startThread()