问题
I have a multi module maven project. In which I have initialized a static hashmap in a common module. I am inserting values in that hashmap in other module called controller and when I want to iterate that hashmap in third module then it gives null.
Here is my static hashmap initialization:
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);
}
}
}
In this I get hashmap null.
来源:https://stackoverflow.com/questions/30373115/static-hashmap-not-working