doStartThread() — netty Function Reference
Architecture documentation for the doStartThread() function in SingleThreadEventExecutor.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 8eb7fcd3_fddd_aede_4b6c_2483c2c54021["doStartThread()"] c9189467_acbc_07ea_3a8c_fecfe22ec122["SingleThreadEventExecutor"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|defined in| c9189467_acbc_07ea_3a8c_fecfe22ec122 2df06e90_ae68_2dbc_f754_10fc8d9ce8f6["startThread()"] 2df06e90_ae68_2dbc_f754_10fc8d9ce8f6 -->|calls| 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 a492b7bc_add7_4389_0b97_074f0f1429af["ensureThreadStarted()"] a492b7bc_add7_4389_0b97_074f0f1429af -->|calls| 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 4b4e2a57_ff72_0b7e_a075_ec9d6f860ef0["run()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| 4b4e2a57_ff72_0b7e_a075_ec9d6f860ef0 ced7700b_627f_0ab1_ff34_9e3824dfeea8["execute()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| ced7700b_627f_0ab1_ff34_9e3824dfeea8 8846f570_8032_89c9_e9e7_f552f8890802["Runnable()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| 8846f570_8032_89c9_e9e7_f552f8890802 eff74b9f_f1e6_931a_a99c_d708e0ade985["updateLastExecutionTime()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| eff74b9f_f1e6_931a_a99c_d708e0ade985 8788a3e1_4d1c_dfe7_a689_228654574da1["canSuspend()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| 8788a3e1_4d1c_dfe7_a689_228654574da1 2fbe8756_76da_a86e_960c_bf11273a6375["confirmShutdown()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| 2fbe8756_76da_a86e_960c_bf11273a6375 a39dc3f5_53d0_999a_6951_01bf9517a267["cleanup()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| a39dc3f5_53d0_999a_6951_01bf9517a267 f4291ef2_179c_42ad_870a_2283c38d406a["drainTasks()"] 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 -->|calls| f4291ef2_179c_42ad_870a_2283c38d406a style 8eb7fcd3_fddd_aede_4b6c_2483c2c54021 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java lines 1178–1306
private void doStartThread() {
executor.execute(new Runnable() {
@Override
public void run() {
processingLock.lock();
assert thread == null;
thread = Thread.currentThread();
if (interrupted) {
thread.interrupt();
interrupted = false;
}
boolean success = false;
Throwable unexpectedException = null;
updateLastExecutionTime();
boolean suspend = false;
try {
for (;;) {
SingleThreadEventExecutor.this.run();
success = true;
int currentState = state;
if (canSuspend(currentState)) {
if (!STATE_UPDATER.compareAndSet(SingleThreadEventExecutor.this,
ST_SUSPENDING, ST_SUSPENDED)) {
// Try again as the CAS failed.
continue;
}
if (!canSuspend(ST_SUSPENDED) && STATE_UPDATER.compareAndSet(SingleThreadEventExecutor.this,
ST_SUSPENDED, ST_STARTED)) {
// Seems like there was something added to the task queue again in the meantime but we
// were able to re-engage this thread as the event loop thread.
continue;
}
suspend = true;
}
break;
}
} catch (Throwable t) {
unexpectedException = t;
logger.warn("Unexpected exception from an event executor: ", t);
} finally {
boolean shutdown = !suspend;
if (shutdown) {
for (;;) {
// We are re-fetching the state as it might have been shutdown in the meantime.
int oldState = state;
if (oldState >= ST_SHUTTING_DOWN || STATE_UPDATER.compareAndSet(
SingleThreadEventExecutor.this, oldState, ST_SHUTTING_DOWN)) {
break;
}
}
if (success && gracefulShutdownStartTime == 0) {
// Check if confirmShutdown() was called at the end of the loop.
if (logger.isErrorEnabled()) {
logger.error("Buggy " + EventExecutor.class.getSimpleName() + " implementation; " +
SingleThreadEventExecutor.class.getSimpleName() + ".confirmShutdown() must " +
"be called before run() implementation terminates.");
}
}
}
try {
if (shutdown) {
// Run all remaining tasks and shutdown hooks. At this point the event loop
// is in ST_SHUTTING_DOWN state still accepting tasks which is needed for
// graceful shutdown with quietPeriod.
for (;;) {
if (confirmShutdown()) {
break;
}
}
// Now we want to make sure no more tasks can be added from this point. This is
// achieved by switching the state. Any new tasks beyond this point will be rejected.
for (;;) {
int currentState = state;
if (currentState >= ST_SHUTDOWN || STATE_UPDATER.compareAndSet(
SingleThreadEventExecutor.this, currentState, ST_SHUTDOWN)) {
break;
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does doStartThread() do?
doStartThread() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java.
Where is doStartThread() defined?
doStartThread() is defined in common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java at line 1178.
What does doStartThread() call?
doStartThread() calls 8 function(s): Runnable, canSuspend, cleanup, confirmShutdown, drainTasks, execute, run, updateLastExecutionTime.
What calls doStartThread()?
doStartThread() is called by 2 function(s): ensureThreadStarted, startThread.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free