Home / Class/ RecyclerFastThreadLocalTest Class — netty Architecture

RecyclerFastThreadLocalTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  785d6cb4_3c02_ed7e_3786_f92f3033392b["RecyclerFastThreadLocalTest"]
  a1d123f0_5fdc_f050_3e19_6fe3c54e4664["RecyclerFastThreadLocalTest.java"]
  785d6cb4_3c02_ed7e_3786_f92f3033392b -->|defined in| a1d123f0_5fdc_f050_3e19_6fe3c54e4664
  dc2a67b8_8ee3_2508_c137_9fcf967ac4a3["Thread()"]
  785d6cb4_3c02_ed7e_3786_f92f3033392b -->|method| dc2a67b8_8ee3_2508_c137_9fcf967ac4a3
  d8f9d3a3_3377_f367_9708_cc358351a7a5["testThreadCanBeCollectedEvenIfHandledObjectIsReferenced()"]
  785d6cb4_3c02_ed7e_3786_f92f3033392b -->|method| d8f9d3a3_3377_f367_9708_cc358351a7a5

Relationship Graph

Source Code

common/src/test/java/io/netty/util/RecyclerFastThreadLocalTest.java lines 31–85

@ExtendWith(RunInFastThreadLocalThreadExtension.class)
public class RecyclerFastThreadLocalTest extends RecyclerTest {
    @NotNull
    @Override
    protected Thread newThread(Runnable runnable) {
        return new FastThreadLocalThread(runnable);
    }

    @Override
    @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 FastThreadLocalThread(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();
        }
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free