Java Concurrency: Volatile против final в «каскадных» переменных?
является
final Map<Integer,Map<String,Integer>> status = new ConcurrentHashMap<Integer, Map<String,Integer>>();
Map<Integer,Map<String,Integer>> statusInner = new ConcurrentHashMap<Integer, Map<String,Integer>>();
status.put(key,statusInner);
такой же как
volatile Map<Integer,Map<String,Integer>> status = new ConcurrentHashMap<Integer, Map<String,Integer>>();
Map<Integer,Map<String,Integer>> statusInner = new ConcurrentHashMap<Integer, Map<String,Integer>>();
status.put(key,statusInner);
в случае, если внутренняя карта доступна из разных потоков?
или даже что-то вроде этого требуется:
volatile Map<Integer,Map<String,Integer>> status = new ConcurrentHashMap<Integer, Map<String,Integer>>();
volatile Map<Integer,Map<String,Integer>> statusInner = new ConcurrentHashMap<Integer, Map<String,Integer>>();
status.put(key,statusInner);
В случае, если это НЕ «каскадная» карта, final и volatile имеют в итоге один и тот же эффект, гарантируя, что все потоки всегда будут видеть правильное содержимое карты ... Но что произойдет, если сама карта содержит карту, как в примере ... Как мне убедиться, что внутренняя карта правильно "Память заблокирована"?
Танки! Том