- java.lang.Object
-
- io.netty5.util.concurrent.AbstractEventExecutor
-
- io.netty5.util.concurrent.AbstractScheduledEventExecutor
-
- io.netty5.util.concurrent.GlobalEventExecutor
-
- All Implemented Interfaces:
EventExecutor
,EventExecutorGroup
,FuturePromiseFactory
,OrderedEventExecutor
,Iterable<EventExecutor>
,Executor
public final class GlobalEventExecutor extends AbstractScheduledEventExecutor implements OrderedEventExecutor
Single-thread singletonEventExecutor
. 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.
-
-
Field Summary
Fields Modifier and Type Field Description static GlobalEventExecutor
INSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitInactivity(long timeout, 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, TimeUnit unit)
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.void
execute(Runnable task)
boolean
inEventLoop(Thread thread)
boolean
isShutdown()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.boolean
isShuttingDown()
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.boolean
isTerminated()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.int
pendingTasks()
Return the number of tasks that are pending for processing.Future<Void>
shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down.Future<Void>
terminationFuture()
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.-
Methods inherited from class io.netty5.util.concurrent.AbstractScheduledEventExecutor
cancelScheduledTasks, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, newRunnableScheduledFuture, newScheduledTaskFor, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
-
Methods inherited from class io.netty5.util.concurrent.AbstractEventExecutor
newSucceededFuture, newTaskFor, newTaskFor, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutor
inEventLoop, iterator, newFailedFuture, newPromise, newSucceededFuture, next, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submit, submit, submit
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutorGroup
shutdownGracefully
-
Methods inherited from interface io.netty5.util.concurrent.FuturePromiseFactory
newSucceededFuture
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
INSTANCE
public static final GlobalEventExecutor INSTANCE
-
-
Method Detail
-
pendingTasks
public int pendingTasks()
Return the number of tasks that are pending for processing.
-
inEventLoop
public boolean inEventLoop(Thread thread)
Description copied from interface:EventExecutor
- Specified by:
inEventLoop
in interfaceEventExecutor
-
shutdownGracefully
public Future<Void> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Signals 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. This method 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:
shutdownGracefully
in interfaceEventExecutorGroup
- Parameters:
quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is shutting down regardless if a task was submitted during the quiet period.unit
- the unit ofquietPeriod
andtimeout
- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
public Future<Void> terminationFuture()
Description copied from interface:EventExecutorGroup
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.- Specified by:
terminationFuture
in interfaceEventExecutorGroup
- Returns:
- The
Future
representing the termination of thisEventExecutorGroup
.
-
isShuttingDown
public boolean isShuttingDown()
Description copied from interface:EventExecutorGroup
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.An executor group that "is shutting down" can still accept new tasks for a little while (the grace period), but will eventually start rejecting new tasks. At that point, the executor group will be shut down.
- Specified by:
isShuttingDown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have at least started shutting down, otherwisefalse
.
-
isShutdown
public boolean isShutdown()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.An executor group that "is shut down" might still be executing tasks that it has queued up, but it will no longer be accepting any new tasks. Once all running and queued tasks have completed, the executor group will be terminated.
- Specified by:
isShutdown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have shut down and are no longer accepting any new tasks.
-
isTerminated
public boolean isTerminated()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.- Specified by:
isTerminated
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have terminated.
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.- Specified by:
awaitTermination
in interfaceEventExecutorGroup
- Parameters:
timeout
- The non-negative maximum amount of time to wait for the executor group to terminate.unit
- The non-null time unit of the timeout.- Returns:
true
if the executor group terminated within the specific timeout.
-
awaitInactivity
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:
true
if and only if the worker thread has been terminated- Throws:
InterruptedException
-
execute
public void execute(Runnable task)
- Specified by:
execute
in interfaceEventExecutor
- Specified by:
execute
in interfaceEventExecutorGroup
- Specified by:
execute
in interfaceExecutor
-
-