@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
Log.info("完成", App.sqlCount.get());
Log.info(String.format("finish request... || sql执行次数:%s sql总耗时:%s ms", reqExtProperty.sqlCount.get(), App.sqlDuration.get()));
App.sqlCount.remove();
App.sqlDuration.remove();
App._uniq_req_no.remove();
}
public class App {
public static final String SESSION_USER = "user"; // 用户对象
public static ThreadLocal<String> _uniq_req_no = new ThreadLocal<String>();
public static ThreadLocal<Integer> sqlCount = ThreadLocal.withInitial(() -> 0);
public static ThreadLocal<Long> sqlDuration = ThreadLocal.withInitial(() -> 0L);
}
发现我这样竟然是线程不安全的。
已经是
ThreadLocal
了,按说不会有线程不安全的情况,所以题主遇到了什么样的线程不安全呢?