Static hashmap not working

断了今生、忘了曾经 提交于 2019-12-11 11:49:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!