Class GlobalEventExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
io.netty.util.concurrent.AbstractEventExecutor
io.netty.util.concurrent.AbstractScheduledEventExecutor
io.netty.util.concurrent.GlobalEventExecutor
- All Implemented Interfaces:
EventExecutor, EventExecutorGroup, OrderedEventExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
public final class GlobalEventExecutor
extends AbstractScheduledEventExecutor
implements OrderedEventExecutor
Single-thread singleton
EventExecutor. It starts the thread automatically and stops it when there is no
task pending in the task queue for io.netty.globalEventExecutor.quietPeriodSeconds second
(default is 1 second). Please note it is not scalable to schedule large number of tasks to this executor;
use a dedicated executor.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnable -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitInactivity(long timeout, TimeUnit unit) Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself.booleanawaitTermination(long timeout, TimeUnit unit) voidbooleaninEventLoop(Thread thread) booleanbooleanReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.booleanintReturn the number of tasks that are pending for processing.voidshutdown()Deprecated.Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) Signals this executor that the caller wants the executor to be shut down.Future<?> Returns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.Methods inherited from class AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduledModifier and TypeMethodDescriptionprotected booleanafterScheduledTaskSubmitted(long deadlineNanos) protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.protected voidCancel all scheduled tasks.protected static longdeadlineToDelayNanos(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos, calculate the number of nano seconds from nowdeadlineNanoswould expire.protected longGet the current time in nanoseconds by this executor's clock.protected final booleanReturnstrueif a scheduled task is ready for processing.protected static longThe initial value used for delay and computations based upon a monatomic time source.protected static longnanoTime()Deprecated.Use the non-staticAbstractScheduledEventExecutor.getCurrentTimeNanos()instead.protected final longReturn the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1if no task is scheduled.protected final longReturn the nanoseconds until the next scheduled task is ready to be run or-1if no task is scheduled.protected final Runnableprotected final RunnablepollScheduledTask(long nanoTime) Return theRunnablewhich is ready to be executed with the givennanoTime.<V> ScheduledFuture<V> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) protected voidvalidateScheduled(long amount, TimeUnit unit) Deprecated.will be removed in the future.Methods inherited from class AbstractEventExecutor
inEventLoop, iterator, lazyExecute, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submitModifier and TypeMethodDescriptionbooleanCallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argumentiterator()voidlazyExecute(Runnable task) LikeExecutor.execute(Runnable)but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.<V> Future<V> newFailedFuture(Throwable cause) Create a newFuturewhich is marked as failed already.<V> ProgressivePromise<V> Create a newProgressivePromise.<V> Promise<V> Return a newPromise.<V> Future<V> newSucceededFuture(V result) Create a newFuturewhich is marked as succeeded already.protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable) next()Returns a reference to itself.parent()Return theEventExecutorGroupwhich is the parent of thisEventExecutor,protected static voidprotected static voidsafeExecute(Runnable task) Future<?> Shortcut method forEventExecutorGroup.shutdownGracefully(long, long, TimeUnit)with sensible default values.Future<?> <T> Future<T> <T> Future<T> Methods inherited from class AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAnyMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
INSTANCE
-
-
Method Details
-
pendingTasks
public int pendingTasks()Return the number of tasks that are pending for processing. -
inEventLoop
Description copied from interface:EventExecutor- Specified by:
inEventLoopin interfaceEventExecutor
-
shutdownGracefully
Description copied from interface:EventExecutorGroupSignals this executor that the caller wants the executor to be shut down. Once this method is called,EventExecutorGroup.isShuttingDown()starts to returntrue, and the executor prepares to shut itself down. UnlikeEventExecutorGroup.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.- Specified by:
shutdownGracefullyin interfaceEventExecutorGroup- Parameters:
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 ofquietPeriodandtimeout- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
Description copied from interface:EventExecutorGroupReturns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.- Specified by:
terminationFuturein interfaceEventExecutorGroup
-
shutdown
Deprecated.- Specified by:
shutdownin interfaceEventExecutorGroup- Specified by:
shutdownin interfaceExecutorService- Specified by:
shutdownin classAbstractEventExecutor
-
isShuttingDown
public boolean isShuttingDown()Description copied from interface:EventExecutorGroupReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.- Specified by:
isShuttingDownin interfaceEventExecutorGroup
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService
-
awaitInactivity
Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself. Because a new worker thread will be started again when a new task is submitted, this operation is only useful when you want to ensure that the worker thread is terminated after your application is shut down and there's no chance of submitting a new task afterwards.- Returns:
trueif and only if the worker thread has been terminated- Throws:
InterruptedException
-
execute
-
SingleThreadEventExecutor.wakesUpForTask(Runnable)to re-create this behaviour