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
2 行目にa が出力されないのはなぜですか? のセマンティクスを読みましたが、putIfAbsent
動作することが保証されているはずです。(注: これは大規模な並行プログラムから抽出されたものです...ご覧のとおり、現在はシングルスレッドです。)