ThreadLocal 对象的使用 和原理

@Test
    public void fun1() {
        ThreadLocal<String> t1 = new ThreadLocal<String>();
        t1.set("hello"); //存
        String s = t1.get(); //取
        System.out.println(t1.get());
        t1.remove();//删除
        System.out.println(t1.get());
        System.out.println(s);
    }

它内部是一个Map , 以当前线程做键!

ThreadLocal 用在哪里?

 

猜你喜欢

转载自blog.csdn.net/weixin_41957098/article/details/88776269