Home / Class/ ThreadDeathWatcherTest Class — netty Architecture

ThreadDeathWatcherTest Class — netty Architecture

Architecture documentation for the ThreadDeathWatcherTest class in ThreadDeathWatcherTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4732e020_0588_e2dd_973d_3462f91e7c9e["ThreadDeathWatcherTest"]
  4bbd9d1a_d733_cbd9_e6eb_bed9edb2c67c["ThreadDeathWatcherTest.java"]
  4732e020_0588_e2dd_973d_3462f91e7c9e -->|defined in| 4bbd9d1a_d733_cbd9_e6eb_bed9edb2c67c
  15d9eb4f_be4b_26cf_dd68_27b0df3b8239["testWatch()"]
  4732e020_0588_e2dd_973d_3462f91e7c9e -->|method| 15d9eb4f_be4b_26cf_dd68_27b0df3b8239
  d91df8dd_25e6_3b18_ea4a_8043d4ab40c4["testUnwatch()"]
  4732e020_0588_e2dd_973d_3462f91e7c9e -->|method| d91df8dd_25e6_3b18_ea4a_8043d4ab40c4
  81f03a62_aad1_78d0_7b90_86bef47b09b0["testThreadGroup()"]
  4732e020_0588_e2dd_973d_3462f91e7c9e -->|method| 81f03a62_aad1_78d0_7b90_86bef47b09b0

Relationship Graph

Source Code

common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java lines 32–144

public class ThreadDeathWatcherTest {

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void testWatch() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        final Thread t = new Thread() {
            @Override
            public void run() {
                for (;;) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ignore) {
                        break;
                    }
                }
            }
        };

        final Runnable task = new Runnable() {
            @Override
            public void run() {
                if (!t.isAlive()) {
                    latch.countDown();
                }
            }
        };

        try {
            ThreadDeathWatcher.watch(t, task);
            fail("must reject to watch a non-alive thread.");
        } catch (IllegalArgumentException e) {
            // expected
        }

        t.start();
        ThreadDeathWatcher.watch(t, task);

        // As long as the thread is alive, the task should not run.
        assertFalse(latch.await(750, TimeUnit.MILLISECONDS));

        // Interrupt the thread to terminate it.
        t.interrupt();

        // The task must be run on termination.
        latch.await();
    }

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void testUnwatch() throws Exception {
        final AtomicBoolean run = new AtomicBoolean();
        final Thread t = new Thread() {
            @Override
            public void run() {
                for (;;) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ignore) {
                        break;
                    }
                }
            }
        };

        final Runnable task = new Runnable() {
            @Override
            public void run() {
                run.set(true);
            }
        };

        t.start();

        // Watch and then unwatch.
        ThreadDeathWatcher.watch(t, task);
        ThreadDeathWatcher.unwatch(t, task);

        // Interrupt the thread to terminate it.
        t.interrupt();

Frequently Asked Questions

What is the ThreadDeathWatcherTest class?
ThreadDeathWatcherTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java.
Where is ThreadDeathWatcherTest defined?
ThreadDeathWatcherTest is defined in common/src/test/java/io/netty/util/ThreadDeathWatcherTest.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free