现在的位置: 首页 > 综合 > 正文

Thread local to save a variable for each Thread

2014年12月10日 ⁄ 综合 ⁄ 共 305字 ⁄ 字号 评论关闭

  private static final ThreadLocal < String > tlLogId =
      new ThreadLocal < String > () {
              @Override protected String initialValue() {
                return "unknown";
        }
    };
   
    public static String getLogId() {
        return tlLogId.get();
    }
 
    public static void setLogId(String x) {
        tlLogId.set(x);
    }

 

 

抱歉!评论已关闭.