说明:
分两种方式运行看输出结果(有怪异的结果出现):
方式1.直接run,看输出结果;
方式2.设置断点,然后debug看输出结果.
================================================
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.*;
import java.util.logging.Logger;
public class TestConcurrentMap {
static Map<String,String>map=new HashMap<>();
static ConcurrentMap< String, String>conMap=new ConcurrentHashMap<>();
static Logger log=Logger.getLogger("TestConcurrentMap");
public static void main(String[] args) {
Thread t1=new Thread(){
@Override
public void run() {
//下一行设断点,然后看输出
map.put("1", "1");
conMap.put("1", "1");
}
};
Thread t2=new Thread(){
@Override
public void run() {
map.put("2", "2");
conMap.put("2", "2");
}
};
t1.start();
t2.start();
//下一行设置一个断点,debug执行,看输出结果
// System.out.println(map);
// System.out.println(conMap);
log.info(map.toString());
log.info(conMap.toString());
}
}