Thread Safety of ServletContext objects

后端 未结 5 1487
余生分开走
余生分开走 2020-12-06 13:15

I am storing a HashMap object in my ServletContext. But Multiple Request thread are reading and Modifying this HashMap.

As i belive the ServletContext objects are sh

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 13:33

    As Suggested by @Artem Moskalev, You can use ConcurrentHashMap and use putIfAbsent method to store the object/values instead of simple put method.

    I wanted to add this comment below @Artem Moskalev's answer but i don't have enough reputation for this.

提交回复
热议问题