使用 ThreadLocal 不当可能会导致内存泄露,是什么原因导致的内存泄漏呢?我们首先看一个例子,代码如下:/*Created by cong on 2018/7/14.*/public class ThreadLocalOutOfMemoryTest { static class LocalVariable { private Long[]a=new...
public class RequestHolder { private final static ThreadLocal<Long>requestHolder=new ThreadLocal();提供方法传递数据 public static void add(Long id){ requestHolder.set(id);} public static Long getId(){/传入了当前线程的ID,...
目录一 引言二 源码解析三 案例四 总结一 引言ThreadLocal的官方API解释为:*This class provides thread-local variables.These variables differ from*their normal counterparts in that each thread that accesses one(via its*{@code ...