这是我的测试代码。新的许多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();
}