首页 > 代码库 > ThreadLocal

ThreadLocal

private static ThreadLocal tl = new ThreadLocal();

public static void main(String[] args) {
	
	tl.set("nihao");//容器:Map容器--》[key:当前线程对象,value:nihao]
	
	Object o = tl.get();//默认的key是当前线程
	System.out.println(o);//nihao
	
	tl.remove();//默认的key是当前线程
	
	o = tl.get();
	System.out.println(o);
}

  

技术分享

 

ThreadLocal