run() — netty Function Reference
Architecture documentation for the run() function in GlobalEventExecutor.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9f953b79_2e4a_57b7_6141_d89c69f7af26["run()"] 391a7615_0efb_7213_6501_1dcb645200b7["TaskRunner"] 9f953b79_2e4a_57b7_6141_d89c69f7af26 -->|defined in| 391a7615_0efb_7213_6501_1dcb645200b7 31f472df_5417_844a_9cd1_9eddb4104927["startThread()"] 31f472df_5417_844a_9cd1_9eddb4104927 -->|calls| 9f953b79_2e4a_57b7_6141_d89c69f7af26 72fdbb93_fa1b_91b4_c12e_dc06d2a5f63d["setContextClassLoader()"] 72fdbb93_fa1b_91b4_c12e_dc06d2a5f63d -->|calls| 9f953b79_2e4a_57b7_6141_d89c69f7af26 50f2e551_e181_ef54_3e04_cff754e3a56e["execute()"] 9f953b79_2e4a_57b7_6141_d89c69f7af26 -->|calls| 50f2e551_e181_ef54_3e04_cff754e3a56e 31f472df_5417_844a_9cd1_9eddb4104927["startThread()"] 9f953b79_2e4a_57b7_6141_d89c69f7af26 -->|calls| 31f472df_5417_844a_9cd1_9eddb4104927 style 9f953b79_2e4a_57b7_6141_d89c69f7af26 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java lines 280–328
@Override
public void run() {
for (;;) {
Runnable task = takeTask();
if (task != null) {
try {
runTask(task);
} catch (Throwable t) {
logger.warn("Unexpected exception from the global event executor: ", t);
}
if (task != quietPeriodTask) {
continue;
}
}
Queue<ScheduledFutureTask<?>> scheduledTaskQueue = GlobalEventExecutor.this.scheduledTaskQueue;
// Terminate if there is no task in the queue (except the noop task).
if (taskQueue.isEmpty() && (scheduledTaskQueue == null || scheduledTaskQueue.size() == 1)) {
// Mark the current thread as stopped.
// The following CAS must always success and must be uncontended,
// because only one thread should be running at the same time.
boolean stopped = started.compareAndSet(true, false);
assert stopped;
// Check if there are pending entries added by execute() or schedule*() while we do CAS above.
// Do not check scheduledTaskQueue because it is not thread-safe and can only be mutated from a
// TaskRunner actively running tasks.
if (taskQueue.isEmpty()) {
// A) No new task was added and thus there's nothing to handle
// -> safe to terminate because there's nothing left to do
// B) A new thread started and handled all the new tasks.
// -> safe to terminate the new thread will take care the rest
break;
}
// There are pending tasks added again.
if (!started.compareAndSet(false, true)) {
// startThread() started a new thread and set 'started' to true.
// -> terminate this thread so that the new thread reads from taskQueue exclusively.
break;
}
// New tasks were added, but this worker was faster to set 'started' to true.
// i.e. a new worker thread was not started by startThread().
// -> keep this thread alive to handle the newly added entries.
}
}
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does run() do?
run() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java.
Where is run() defined?
run() is defined in common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java at line 280.
What does run() call?
run() calls 2 function(s): execute, startThread.
What calls run()?
run() is called by 2 function(s): setContextClassLoader, startThread.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free