Home / Function/ testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() — netty Function Reference

testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() — netty Function Reference

Architecture documentation for the testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() function in RecyclerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7e725c35_0fe0_4456_3792_5bd564cc5c6c["testThreadCanBeCollectedEvenIfHandledObjectIsReferenced()"]
  46ac14b1_2382_5afa_98f3_803182070b38["RecyclerTest"]
  7e725c35_0fe0_4456_3792_5bd564cc5c6c -->|defined in| 46ac14b1_2382_5afa_98f3_803182070b38
  1c2c7a05_5ecb_99ce_ba33_27c123c22ebe["Thread()"]
  7e725c35_0fe0_4456_3792_5bd564cc5c6c -->|calls| 1c2c7a05_5ecb_99ce_ba33_27c123c22ebe
  87dca999_f804_a974_e326_fd8f527f1246["newRecycler()"]
  7e725c35_0fe0_4456_3792_5bd564cc5c6c -->|calls| 87dca999_f804_a974_e326_fd8f527f1246
  43ab40f6_52e7_0fe9_a79f_220021939268["recycle()"]
  7e725c35_0fe0_4456_3792_5bd564cc5c6c -->|calls| 43ab40f6_52e7_0fe9_a79f_220021939268
  style 7e725c35_0fe0_4456_3792_5bd564cc5c6c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/test/java/io/netty/util/RecyclerTest.java lines 169–213

    @ParameterizedTest
    @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
    @MethodSource("ownerTypeAndUnguarded")
    public void testThreadCanBeCollectedEvenIfHandledObjectIsReferenced(OwnerType ownerType, boolean unguarded)
            throws Exception {
        final AtomicBoolean collected = new AtomicBoolean();
        final AtomicReference<HandledObject> reference = new AtomicReference<HandledObject>();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                final Recycler<HandledObject> recycler = newRecycler(ownerType, unguarded, 1024);
                HandledObject object = recycler.get();
                // Store a reference to the HandledObject to ensure it is not collected when the run method finish.
                reference.set(object);
                Recycler.unpinOwner(recycler);
            }
        }) {
            @Override
            protected void finalize() throws Throwable {
                try {
                    collected.set(true);
                } finally {
                    super.finalize();
                }
            }
        };
        assertFalse(collected.get());
        thread.start();
        thread.join();

        // Null out so it can be collected.
        thread = null;

        // Loop until the Thread was collected. If we can not collect it the Test will fail due of a timeout.
        while (!collected.get()) {
            System.gc();
            System.runFinalization();
            Thread.sleep(50);
        }

        // Now call recycle after the Thread was collected to ensure this still works...
        if (reference.get() != null) {
            reference.getAndSet(null).recycle();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() do?
testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() is a function in the netty codebase, defined in common/src/test/java/io/netty/util/RecyclerTest.java.
Where is testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() defined?
testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() is defined in common/src/test/java/io/netty/util/RecyclerTest.java at line 169.
What does testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() call?
testThreadCanBeCollectedEvenIfHandledObjectIsReferenced() calls 3 function(s): Thread, newRecycler, recycle.

Analyze Your Own Codebase

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

Try Supermodel Free