我有一个多模块maven项目。我在其中初始化了一个公共模块中的静态hashmap。我在其他模块中的hashmap中插入值,当我想在第三个模块中迭代该hashmap时,它会给出null。
这是我的静态hashmap初始化:
public static HashMap<String, Integer> hmSimultaneousRequestTracker = new HashMap<String, Integer>();
Controller module:
Constants.hmSimultaneousRequestTracker.put(inputjson.getSettings().getUsername(),1);
Third module:
for (Map.Entry<String, Integer> entry : Constants.hmSimultaneousRequestTracker.entrySet()) {
if(entry.getKey().equals(username)){
if(entry.getValue()>0);
{
int value = entry.getValue()-1 ;
entry.setValue(value);
}
}
}
在此我得到了hashmap null。