【发布时间】:2013-10-01 19:55:12
【问题描述】:
public static void main(String args[]) throws Exception {
ConcurrentHashMap<byte[], Integer> dps =
new ConcurrentHashMap<byte[], Integer>();
System.out.println(dps.putIfAbsent("hi".getBytes(), 1));
System.out.println(dps.putIfAbsent("hi".getBytes(), 1));
}
打印
null
null
为什么不在第二行打印1?我已经阅读了putIfAbsent 的语义,应该保证它可以工作。 (注意:这是从一个大型并发程序中提炼出来的……如您所见,它现在是单线程的。)
【问题讨论】:
标签: java concurrency hashmap concurrenthashmap