Concurrent Modification exception while accessing Spring bean class

I am having a web application which is running on tomcat server and on java 11. I have a spring bean class like


public class PatternMatcher {

private Map patterns = new HashMap<>();

String regEx = "(?i)apc\.[A-z]{2}\.011\.[0-9]+\.02.*";

public boolean isAMatch(String exp){

return getMatcherPattern().matcher(exp).matches();


private Pattern getMatcherPattern(){

return patterns.computeIfAbsent(regex, Pattern::compile);



This class is injected in some other classes and its working fine in my local and in test environments. But in production, I am seeing intermittent logs like

java.util.ConcurrentModificationException: null

at java.base/java.util.HashMap.computeIfAbsent(Unknown Source)

Is it because multiple requests are accessing the map? If yes will using a ConcurrentHashmap fix...

Read More »

By: StackOverFlow - 6 days ago

Related Posts