ThreadLocal 緩存存入線程,防止其餘出現線程污染問題

https://www.cnblogs.com/coshaho/p/5127135.htmlhtml

 

// ThreadLocal裏只存儲了簡單的String對象,也能夠本身定義對象,存儲更加複雜的參數
    private static ThreadLocal<String> threadLocal = new ThreadLocal<String>();post

    public static String getPostRequestParams(){
        return threadLocal.get();
    }htm

    public static void setPostRequestParams(String postRequestParams){
        threadLocal.set(postRequestParams);
    }對象

    public static void removePostRequestParams(){
        threadLocal.remove();
    }blog

相關文章
相關標籤/搜索