File tree Expand file tree Collapse file tree
config/src/main/java/com/alibaba/nacos/config/server/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919import com .alibaba .nacos .config .server .utils .SimpleReadWriteLock ;
2020import com .alibaba .nacos .core .utils .StringPool ;
2121
22- import java .util .HashMap ;
2322import java .util .List ;
2423import java .util .Map ;
24+ import java .util .concurrent .ConcurrentHashMap ;
2525import java .util .stream .Collectors ;
2626
2727/**
@@ -80,7 +80,11 @@ public String getGroupKey() {
8080 */
8181 public void initConfigGrayIfEmpty () {
8282 if (this .configCacheGray == null ) {
83- this .configCacheGray = new HashMap <>(4 );
83+ synchronized (this ) {
84+ if (this .configCacheGray == null ) {
85+ this .configCacheGray = new ConcurrentHashMap <>(4 );
86+ }
87+ }
8488 }
8589 }
8690
@@ -91,9 +95,8 @@ public void initConfigGrayIfEmpty() {
9195 */
9296 public void initConfigGrayIfEmpty (String grayName ) {
9397 initConfigGrayIfEmpty ();
94- if (!this .configCacheGray .containsKey (grayName )) {
95- this .configCacheGray .put (grayName , ConfigCacheFactoryDelegate .getInstance ().createConfigCacheGray (grayName ));
96- }
98+ this .configCacheGray .computeIfAbsent (grayName ,
99+ k -> ConfigCacheFactoryDelegate .getInstance ().createConfigCacheGray (k ));
97100 }
98101
99102 public List <ConfigCacheGray > getSortConfigGrays () {
You can’t perform that action at this time.
0 commit comments