Top Description Inners Fields Constructors Methods
io.netty.util.concurrent

public final Class GlobalEventExecutor

extends AbstractScheduledEventExecutor
implements OrderedEventExecutor
Class Inheritance
All Implemented Interfaces
io.netty.util.concurrent.OrderedEventExecutor, io.netty.util.concurrent.EventExecutor, io.netty.util.concurrent.EventExecutorGroup, java.lang.Iterable, java.util.concurrent.ScheduledExecutorService, java.util.concurrent.ExecutorService, java.lang.AutoCloseable, java.util.concurrent.Executor
Imports
io.netty.util.internal.ObjectUtil, .SystemPropertyUtil, .ThreadExecutorMap, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, org.jetbrains.annotations.Async.Schedule, java.security.AccessController, .PrivilegedAction, java.util.Queue, java.util.concurrent.BlockingQueue, .Executors, .LinkedBlockingQueue, .RejectedExecutionException, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean

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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
public static final GlobalEventExecutor
private static final InternalLogger
pack-priv final ScheduledFutureTask<Void>
private static final long
private final AtomicBoolean
pack-priv final BlockingQueue<Runnable>
private final GlobalEventExecutor.TaskRunner
private final Future<?>
pack-priv volatile Thread
pack-priv final ThreadFactory
Inherited from io.netty.util.concurrent.AbstractScheduledEventExecutor:
nextTaskIdscheduledTaskQueueWAKEUP_TASK

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
addTask(Runnable task)

Add a task to the task queue, or throws a RejectedExecutionException if this instance was shutdown before.

public boolean

Returns:

true if and only if the worker thread has been terminated
awaitInactivity
(long timeout, TimeUnit unit)

Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself.

public boolean
awaitTermination(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
public void
execute(Runnable
the runnable task
task
)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.
private void
private void
public boolean
inEventLoop(Thread thread)

Implements io.netty.util.concurrent.EventExecutor.inEventLoop.

Return true if the given Thread is executed in the event loop, false otherwise.
public boolean
isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.
public boolean
public boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.
public int
pendingTasks()

Return the number of tasks that are pending for processing.

public void
shutdown()

Implements abstract io.netty.util.concurrent.AbstractEventExecutor.shutdown.

Implements io.netty.util.concurrent.EventExecutorGroup.shutdown, java.util.concurrent.ExecutorService.shutdown.

Deprecated
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
public Future<?>
shutdownGracefully(long
the quiet period as described in the documentation
quietPeriod
,
long
the maximum amount of time to wait until the executor is shutdown() regardless if a task was submitted during the quiet period
timeout
,
TimeUnit
the unit of quietPeriod and timeout
unit
)

Implements io.netty.util.concurrent.EventExecutorGroup.shutdownGracefully.

Signals this executor that the caller wants the executor to be shut down.
private void
pack-priv Runnable

Returns:

null if the executor thread has been interrupted or waken up.
takeTask
()

Take the next Runnable from the task queue and so will block if no task is currently present.

public Future<?>
terminationFuture()

Implements io.netty.util.concurrent.EventExecutorGroup.terminationFuture.

Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
Inherited from io.netty.util.concurrent.AbstractScheduledEventExecutor:
afterScheduledTaskSubmittedbeforeScheduledTaskSubmittedcancelScheduledTasksdeadlineNanosdeadlineToDelayNanosdefaultCurrentTimeNanosgetCurrentTimeNanoshasScheduledTasksinitialNanoTimenanoTimenextScheduledTaskDeadlineNanosnextScheduledTaskNanopeekScheduledTaskpollScheduledTaskpollScheduledTaskremoveScheduledscheduleschedulescheduleAtFixedRatescheduledTaskQueuescheduleFromEventLoopscheduleWithFixedDelayvalidateScheduled

Field Detail

INSTANCEback to summary
public static final GlobalEventExecutor INSTANCE
loggerback to summary
private static final InternalLogger logger

Hides io.netty.util.concurrent.AbstractEventExecutor.logger.

quietPeriodTaskback to summary
pack-priv final ScheduledFutureTask<Void> quietPeriodTask
SCHEDULE_QUIET_PERIOD_INTERVALback to summary
private static final long SCHEDULE_QUIET_PERIOD_INTERVAL
startedback to summary
private final AtomicBoolean started
taskQueueback to summary
pack-priv final BlockingQueue<Runnable> taskQueue
taskRunnerback to summary
private final GlobalEventExecutor.TaskRunner taskRunner
terminationFutureback to summary
private final Future<?> terminationFuture
threadback to summary
pack-priv volatile Thread thread
threadFactoryback to summary
pack-priv final ThreadFactory threadFactory

Constructor Detail

GlobalEventExecutorback to summary
private GlobalEventExecutor()

Method Detail

addTaskback to summary
private void addTask(Runnable task)

Add a task to the task queue, or throws a RejectedExecutionException if this instance was shutdown before.

awaitInactivityback to summary
public boolean awaitInactivity(long timeout, TimeUnit unit) throws InterruptedException

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:boolean

true if and only if the worker thread has been terminated

awaitTerminationback to summary
public boolean awaitTermination(long timeout, TimeUnit unit)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Doc from java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:boolean

true if this executor terminated and false if the timeout elapsed before termination

Annotations
@Override
executeback to summary
public void execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
task:Runnable

the runnable task

Annotations
@Override
execute0back to summary
private void execute0(Runnable task)
fetchFromScheduledTaskQueueback to summary
private void fetchFromScheduledTaskQueue()
inEventLoopback to summary
public boolean inEventLoop(Thread thread)

Implements io.netty.util.concurrent.EventExecutor.inEventLoop.

Doc from io.netty.util.concurrent.EventExecutor.inEventLoop.

Return true if the given Thread is executed in the event loop, false otherwise.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Doc from java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

Returns:boolean

true if this executor has been shut down

Annotations
@Override
isShuttingDownback to summary
public boolean isShuttingDown()

Implements io.netty.util.concurrent.EventExecutorGroup.isShuttingDown.

Doc from io.netty.util.concurrent.EventExecutorGroup.isShuttingDown.

Returns true if and only if all EventExecutors managed by this EventExecutorGroup are being shut down gracefully or was shut down.

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Doc from java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:boolean

true if all tasks have completed following shut down

Annotations
@Override
pendingTasksback to summary
public int pendingTasks()

Return the number of tasks that are pending for processing.

shutdownback to summary
public void shutdown()

Implements abstract io.netty.util.concurrent.AbstractEventExecutor.shutdown.

Implements io.netty.util.concurrent.EventExecutorGroup.shutdown, java.util.concurrent.ExecutorService.shutdown.

Doc from java.util.concurrent.ExecutorService.shutdown.

Deprecated

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

Annotations
@Override
@Deprecated
shutdownGracefullyback to summary
public Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)

Implements io.netty.util.concurrent.EventExecutorGroup.shutdownGracefully.

Doc from io.netty.util.concurrent.EventExecutorGroup.shutdownGracefully.

Signals this executor that the caller wants the executor to be shut down. Once this method is called, isShuttingDown() starts to return true, and the executor prepares to shut itself down. Unlike 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.

Parameters
quietPeriod:long

the quiet period as described in the documentation

timeout:long

the maximum amount of time to wait until the executor is shutdown() regardless if a task was submitted during the quiet period

unit:TimeUnit

the unit of quietPeriod and timeout

Returns:Future<?>

the terminationFuture()

Annotations
@Override
startThreadback to summary
private void startThread()
takeTaskback to summary
pack-priv Runnable takeTask()

Take the next Runnable from the task queue and so will block if no task is currently present.

Returns:Runnable

null if the executor thread has been interrupted or waken up.

terminationFutureback to summary
public Future<?> terminationFuture()

Implements io.netty.util.concurrent.EventExecutorGroup.terminationFuture.

Doc from io.netty.util.concurrent.EventExecutorGroup.terminationFuture.

Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.

Annotations
@Override
io.netty.util.concurrent back to summary

pack-priv final Class GlobalEventExecutor.TaskRunner

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TaskRunnerback to summary
pack-priv TaskRunner()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override