Repository: netty/netty
File: buffer/src/test/java/io/netty/buffer/AdaptiveByteBufAllocatorUseCacheForNonEventLoopThreadsTest.java (Java)

Code before:
    @Test
    void testFastThreadLocalThreadWithoutCleanupFastThreadLocals() throws InterruptedException {
        final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
        Runnable task = new Runnable() {
            @Override
            public void run() {
                try {
                    AdaptiveByteBufAllocatorUseCacheForNonEventLoopThreadsTest.super.testUsedHeapMemory();
                    AdaptiveByteBufAllocatorUseCacheForNonEventLoopThreadsTest.super.testUsedDirectMemory();
                } catch (Throwable e) {
                    throwable.set(e);
                }
            }
        };
        Thread customizefastThreadLocalThread = new CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals(task);
        customizefastThreadLocalThread.start();
        customizefastThreadLocalThread.join();
        assertNull(throwable.get());
    }

    private static final class CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals
            extends FastThreadLocalThread implements Runnable {
        private final Runnable runnable;
        private CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals(Runnable runnable) {
            this.runnable = ObjectUtil.checkNotNull(runnable, "runnable");
        }
        @Override
        public boolean willCleanupFastThreadLocals() {
            return false;
        }
        @Override
        public void run() {
            runnable.run(); // Without calling `FastThreadLocal.removeAll()`.
        }
    }
}


Review comment (suggestion):
```suggestion

        private CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals(Runnable runnable) {
```

Code after:
    @Test
    void testFastThreadLocalThreadWithoutCleanupFastThreadLocals() throws InterruptedException {
        final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
        Runnable task = new Runnable() {
            @Override
            public void run() {
                try {
                    AdaptiveByteBufAllocatorUseCacheForNonEventLoopThreadsTest.super.testUsedHeapMemory();
                    AdaptiveByteBufAllocatorUseCacheForNonEventLoopThreadsTest.super.testUsedDirectMemory();
                } catch (Throwable e) {
                    throwable.set(e);
                }
            }
        };
        Thread customizefastThreadLocalThread = new CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals(task);
        customizefastThreadLocalThread.start();
        customizefastThreadLocalThread.join();
        assertNull(throwable.get());
    }

    private static final class CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals
            extends FastThreadLocalThread implements Runnable {

        private final Runnable runnable;

        private CustomizeFastThreadLocalThreadWithoutCleanupFastThreadLocals(Runnable runnable) {
            this.runnable = ObjectUtil.checkNotNull(runnable, "runnable");
        }

        @Override
        public boolean willCleanupFastThreadLocals() {
            return false;
        }

        @Override
        public void run() {
            runnable.run(); // Without calling `FastThreadLocal.removeAll()`.
        }
    }
}