Статическая параллельная карта, общая для компонентов, дает разные значения [закрыто] ⇐ JAVA
-
Anonymous
Статическая параллельная карта, общая для компонентов, дает разные значения [закрыто]
I have 2 components A & B in same project that have access to a concurrent hashmap located in component A and do some put and get operations on it.
I designed this class:
public class CondifMsgFields { private static final ConcurrentHashMap numbers = new ConcurrentHashMap(); private CondifMsgFields() { super(); } public static String getX (..., ... , ...) { // Do some put and get on values of the map. } Result is that the map is shared correctly between classes from a given component, but not across components.
That is, when I display keys + values of the map called from classes in component A, it has different keys and values from the one displayed in classes from component B.
I'm fairly new to Java and I'm sure I'm missing something, but I don't quite understand how a static call seem to instantiate two different maps?
Источник: https://stackoverflow.com/questions/780 ... ent-values
I have 2 components A & B in same project that have access to a concurrent hashmap located in component A and do some put and get operations on it.
I designed this class:
public class CondifMsgFields { private static final ConcurrentHashMap numbers = new ConcurrentHashMap(); private CondifMsgFields() { super(); } public static String getX (..., ... , ...) { // Do some put and get on values of the map. } Result is that the map is shared correctly between classes from a given component, but not across components.
That is, when I display keys + values of the map called from classes in component A, it has different keys and values from the one displayed in classes from component B.
I'm fairly new to Java and I'm sure I'm missing something, but I don't quite understand how a static call seem to instantiate two different maps?
Источник: https://stackoverflow.com/questions/780 ... ent-values
Мобильная версия