ThreadLocal 缓存存入线程,防止其他出现线程污染问题

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

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

 

// ThreadLocal里只存储了简单的String对象,也可以自己定义对象,存储更加复杂的参数
    private static ThreadLocal threadLocal = new ThreadLocal();

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

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

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

转载于:https://my.oschina.net/u/2400545/blog/1830921

你可能感兴趣的:(ThreadLocal 缓存存入线程,防止其他出现线程污染问题)