每周有营养的大厂算法面试题
private SingletonObject() {
// ... expensive operations
}}// ConcurrentHashMap 多个操作联级class Main {
public static Map<String, Object> values = new ConcurrentHashMap();
public static void main(String[] args) {
// 多个操作联级,不是原子的
// 使用 values.putIfAbsent("key", calculate("")); 代替
if (!values.containsKey("key")) {
values.put("key", calculate(""));
}
}