ThreadLocal
使用方法
// java.lang.Thread.java
public class SafeDateFormat {
private static final ThreadLocal<SimpleDateFormat> th =
ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
public static DateFormat get() {
return th.get();
}
}原理实现
注意事项
内存泄漏
InheritableThreadLocal
Last updated
