From 3b27083c440dc5964c974d37242714e5899356fd Mon Sep 17 00:00:00 2001 From: uniquewings Date: Mon, 10 Jul 2023 17:26:12 +0800 Subject: [PATCH] Fix a reace condition caused by one thread calls getMapper method while other threads calling addMapper fix the issue 2890: https://github.com/mybatis/mybatis-3/issues/2890 --- src/main/java/org/apache/ibatis/binding/MapperRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/ibatis/binding/MapperRegistry.java b/src/main/java/org/apache/ibatis/binding/MapperRegistry.java index f3484ac64b2..a87cbb09102 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperRegistry.java +++ b/src/main/java/org/apache/ibatis/binding/MapperRegistry.java @@ -17,9 +17,9 @@ import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder; import org.apache.ibatis.io.ResolverUtil; @@ -34,7 +34,7 @@ public class MapperRegistry { private final Configuration config; - private final Map, MapperProxyFactory> knownMappers = new HashMap<>(); + private final Map, MapperProxyFactory> knownMappers = new ConcurrentHashMap<>(); public MapperRegistry(Configuration config) { this.config = config;