public class ThreadLocalTest {
private  ThreadLocal local =new ThreadLocal();
private Map testMap =new HashMap();
private void initMap(){
this.testMap.put("key1","caojinli");
this.testMap.put("key2","xiaofei");
this.local.set(testMap);
}
public Map getTestMap() {
return testMap;
}
public void setTestMap(Map testMap) {
this.testMap = testMap;
}
public void getDatafromMap(){
String name =(String)testMap.get("key1");
if(name==null){
Map map =(Map)local.get();
name =(String)map.get("key1");
}
System.out.println(name);
}
public static void main(String[] args){
ThreadLocalTest threadlocalTest  =new ThreadLocalTest();
threadlocalTest.initMap();
ANewThread newThread =new ANewThread();
                 /*
                  public class ANewThread extends Thread{
                  public void changeMap(Map map){
            map.put("key3","wuyanfei");
                }                     }                  */
newThread.changeMap(threadlocalTest.getTestMap());
threadlocalTest.getDatafromMap();
}
}
如何来保证这个map不会被别的线程来修改!
高人指点!