You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/05/16 02:04:04 UTC

[GitHub] [shardingsphere] cherrylzhao commented on a change in pull request #5634: Defect more when concurrently registering services

cherrylzhao commented on a change in pull request #5634:
URL: https://github.com/apache/shardingsphere/pull/5634#discussion_r426106879



##########
File path: shardingsphere-spi/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingSphereServiceLoader.java
##########
@@ -51,17 +51,12 @@
             registerServiceClass(service, each);
         }
     }
-    
-    @SuppressWarnings("unchecked")
+
     private static <T> void registerServiceClass(final Class<T> service, final T instance) {
-        Collection<Class<?>> serviceClasses = SERVICE_MAP.get(service);
-        if (null == serviceClasses) {
-            serviceClasses = new LinkedHashSet<>();
-        }
+        Collection<Class<?>> serviceClasses = SERVICE_MAP.computeIfAbsent(service, unused -> new LinkedHashSet<>());
         serviceClasses.add(instance.getClass());
-        SERVICE_MAP.put(service, serviceClasses);
     }
-    
+

Review comment:
       should keep incident in new line

##########
File path: shardingsphere-spi/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingSphereServiceLoader.java
##########
@@ -73,7 +68,7 @@
     public static <T> Collection<T> newServiceInstances(final Class<T> service) {
         return SERVICE_MAP.containsKey(service) ? SERVICE_MAP.get(service).stream().map(each -> (T) newServiceInstance(each)).collect(Collectors.toList()) : Collections.emptyList();
     }
-    
+

Review comment:
       should keep incident in new line




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org