FastThreadLocal是否存在内存泄漏?

时间:2019-12-06 08:11:04

标签: java netty

这是我的测试代码。新的许多FastThreadLocal实例都有一个test0()函数。当test0()完成时,我看到InternalThreadLocalMap仍然具有以“ helloworld-”开头的1000值。

泄漏吗?

public static void main(String[] args) {
    new FastThreadLocalThread(new Runnable() {
      @Override
      public void run() {
        test0();
        // exec gc
        System.gc();
        FastThreadLocalThread t = (FastThreadLocalThread)Thread.currentThread();
        for (int i = 1; i <= 1000; i++) {
          // still output "helloworld-xxx"
          System.out.println(t.threadLocalMap().indexedVariable(i));
        }
      }

      private void test0() {
        for (int i = 0; i < 1000; i++) {
          final int finalI = i;
          FastThreadLocal<String> test = new FastThreadLocal<String>() {
            protected String initialValue() throws Exception {
              return "helloworld-" + finalI;
            }
          };
          test.get();
        }
      }
    }).start();
  }

0 个答案:

没有答案