run() — netty Function Reference
Architecture documentation for the run() function in ThreadDeathWatcher.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 2e12d8f3_2a76_c115_2e1f_27af3c853d54["run()"] 5f6d0707_3005_8256_7c2d_19661826552d["Watcher"] 2e12d8f3_2a76_c115_2e1f_27af3c853d54 -->|defined in| 5f6d0707_3005_8256_7c2d_19661826552d 52d983df_3c33_cc34_17dc_62af3798f3ef["schedule()"] 52d983df_3c33_cc34_17dc_62af3798f3ef -->|calls| 2e12d8f3_2a76_c115_2e1f_27af3c853d54 666cccad_fc12_bc19_59b3_051276b803c6["notifyWatchees()"] 666cccad_fc12_bc19_59b3_051276b803c6 -->|calls| 2e12d8f3_2a76_c115_2e1f_27af3c853d54 d63c9c90_1e42_7586_aab0_7f19f87736ba["fetchWatchees()"] 2e12d8f3_2a76_c115_2e1f_27af3c853d54 -->|calls| d63c9c90_1e42_7586_aab0_7f19f87736ba 666cccad_fc12_bc19_59b3_051276b803c6["notifyWatchees()"] 2e12d8f3_2a76_c115_2e1f_27af3c853d54 -->|calls| 666cccad_fc12_bc19_59b3_051276b803c6 d0ccf1bb_8ca7_fdeb_a3d1_eecc0fd357d4["watch()"] 2e12d8f3_2a76_c115_2e1f_27af3c853d54 -->|calls| d0ccf1bb_8ca7_fdeb_a3d1_eecc0fd357d4 bcd89545_0ae1_7935_4b1c_1e03947be6b7["unwatch()"] 2e12d8f3_2a76_c115_2e1f_27af3c853d54 -->|calls| bcd89545_0ae1_7935_4b1c_1e03947be6b7 style 2e12d8f3_2a76_c115_2e1f_27af3c853d54 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/ThreadDeathWatcher.java lines 150–195
@Override
public void run() {
for (;;) {
fetchWatchees();
notifyWatchees();
// Try once again just in case notifyWatchees() triggered watch() or unwatch().
fetchWatchees();
notifyWatchees();
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
// Ignore the interrupt; do not terminate until all tasks are run.
}
if (watchees.isEmpty() && pendingEntries.isEmpty()) {
// Mark the current worker thread as stopped.
// The following CAS must always success and must be uncontended,
// because only one watcher thread should be running at the same time.
boolean stopped = started.compareAndSet(true, false);
assert stopped;
// Check if there are pending entries added by watch() while we do CAS above.
if (pendingEntries.isEmpty()) {
// A) watch() was not invoked and thus there's nothing to handle
// -> safe to terminate because there's nothing left to do
// B) a new watcher thread started and handled them all
// -> safe to terminate the new watcher thread will take care the rest
break;
}
// There are pending entries again, added by watch()
if (!started.compareAndSet(false, true)) {
// watch() started a new watcher thread and set 'started' to true.
// -> terminate this thread so that the new watcher reads from pendingEntries exclusively.
break;
}
// watch() added an entry, but this worker was faster to set 'started' to true.
// i.e. a new watcher thread was not started
// -> keep this thread alive to handle the newly added entries.
}
}
}
Domain
Subdomains
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/ThreadDeathWatcher.java.
Where is run() defined?
run() is defined in common/src/main/java/io/netty/util/ThreadDeathWatcher.java at line 150.
What does run() call?
run() calls 4 function(s): fetchWatchees, notifyWatchees, unwatch, watch.
What calls run()?
run() is called by 2 function(s): notifyWatchees, schedule.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free