GlobalEventExecutor Class — netty Architecture
Architecture documentation for the GlobalEventExecutor class in GlobalEventExecutor.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 408381e8_b0ab_c53d_3b6c_8d8a15aaa884["GlobalEventExecutor"] b64f70b1_1ecd_fc71_d0ac_3c49aebb5e9e["GlobalEventExecutor.java"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|defined in| b64f70b1_1ecd_fc71_d0ac_3c49aebb5e9e f96bba37_e49a_2af7_7274_cbb17ef04ae9["GlobalEventExecutor()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| f96bba37_e49a_2af7_7274_cbb17ef04ae9 d2063834_69ba_5d89_1375_f14b3f8cba35["Runnable()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| d2063834_69ba_5d89_1375_f14b3f8cba35 411270ac_1d47_f717_3023_68be625f3871["fetchFromScheduledTaskQueue()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| 411270ac_1d47_f717_3023_68be625f3871 db53d9aa_f858_2333_924f_b43c597b0f4e["pendingTasks()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| db53d9aa_f858_2333_924f_b43c597b0f4e 2e6ec942_d470_ee68_e980_b52424b44122["addTask()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| 2e6ec942_d470_ee68_e980_b52424b44122 8c3d26d7_9eb5_8b59_29b5_6800113feb3c["inEventLoop()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| 8c3d26d7_9eb5_8b59_29b5_6800113feb3c 4308c977_5027_8a8a_2e65_7dd26557e747["shutdownGracefully()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| 4308c977_5027_8a8a_2e65_7dd26557e747 c979b115_fa34_14aa_4c2e_2fa986c2e134["terminationFuture()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| c979b115_fa34_14aa_4c2e_2fa986c2e134 28f94f0c_68ba_c5ec_c9e4_3583c19c8f20["shutdown()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| 28f94f0c_68ba_c5ec_c9e4_3583c19c8f20 cd1ccf6b_7bad_ccd6_018b_4dbb57f7257a["isShuttingDown()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| cd1ccf6b_7bad_ccd6_018b_4dbb57f7257a d670c2b4_b13e_10b6_d042_89097b4ac188["isShutdown()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| d670c2b4_b13e_10b6_d042_89097b4ac188 ddff326c_f3ba_ae4a_952b_4751486d2ba8["isTerminated()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| ddff326c_f3ba_ae4a_952b_4751486d2ba8 a94c4d63_0b9e_2dc5_9658_16ca9a6f3215["awaitTermination()"] 408381e8_b0ab_c53d_3b6c_8d8a15aaa884 -->|method| a94c4d63_0b9e_2dc5_9658_16ca9a6f3215
Relationship Graph
Source Code
common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java lines 44–330
public final class GlobalEventExecutor extends AbstractScheduledEventExecutor implements OrderedEventExecutor {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(GlobalEventExecutor.class);
private static final long SCHEDULE_QUIET_PERIOD_INTERVAL;
static {
int quietPeriod = SystemPropertyUtil.getInt("io.netty.globalEventExecutor.quietPeriodSeconds", 1);
if (quietPeriod <= 0) {
quietPeriod = 1;
}
logger.debug("-Dio.netty.globalEventExecutor.quietPeriodSeconds: {}", quietPeriod);
SCHEDULE_QUIET_PERIOD_INTERVAL = TimeUnit.SECONDS.toNanos(quietPeriod);
}
public static final GlobalEventExecutor INSTANCE = new GlobalEventExecutor();
final BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>();
final ScheduledFutureTask<Void> quietPeriodTask = new ScheduledFutureTask<Void>(
this, Executors.<Void>callable(new Runnable() {
@Override
public void run() {
// NOOP
}
}, null),
// note: the getCurrentTimeNanos() call here only works because this is a final class, otherwise the method
// could be overridden leading to unsafe initialization here!
deadlineNanos(getCurrentTimeNanos(), SCHEDULE_QUIET_PERIOD_INTERVAL),
-SCHEDULE_QUIET_PERIOD_INTERVAL
);
// because the GlobalEventExecutor is a singleton, tasks submitted to it can come from arbitrary threads and this
// can trigger the creation of a thread from arbitrary thread groups; for this reason, the thread factory must not
// be sticky about its thread group
// visible for testing
final ThreadFactory threadFactory;
private final TaskRunner taskRunner = new TaskRunner();
private final AtomicBoolean started = new AtomicBoolean();
volatile Thread thread;
private final Future<?> terminationFuture;
private GlobalEventExecutor() {
scheduleFromEventLoop(quietPeriodTask);
threadFactory = ThreadExecutorMap.apply(new DefaultThreadFactory(
DefaultThreadFactory.toPoolName(getClass()), false, Thread.NORM_PRIORITY, null), this);
UnsupportedOperationException terminationFailure = new UnsupportedOperationException();
ThrowableUtil.unknownStackTrace(terminationFailure, GlobalEventExecutor.class, "terminationFuture");
terminationFuture = new FailedFuture<Object>(this, terminationFailure);
}
/**
* Take the next {@link Runnable} from the task queue and so will block if no task is currently present.
*
* @return {@code null} if the executor thread has been interrupted or waken up.
*/
Runnable takeTask() {
BlockingQueue<Runnable> taskQueue = this.taskQueue;
for (;;) {
ScheduledFutureTask<?> scheduledTask = peekScheduledTask();
if (scheduledTask == null) {
Runnable task = null;
try {
task = taskQueue.take();
} catch (InterruptedException e) {
// Ignore
}
return task;
} else {
long delayNanos = scheduledTask.delayNanos();
Runnable task = null;
if (delayNanos > 0) {
try {
task = taskQueue.poll(delayNanos, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
// Waken up.
return null;
}
}
if (task == null) {
Source
Frequently Asked Questions
What is the GlobalEventExecutor class?
GlobalEventExecutor is a class in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java.
Where is GlobalEventExecutor defined?
GlobalEventExecutor is defined in common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java at line 44.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free