You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2023/05/30 02:54:50 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24558: Avoid ConcurrentHashMap recursive update in ShardingSphereServiceLoader.getServiceInstances

sandynz commented on code in PR #24558:
URL: https://github.com/apache/shardingsphere/pull/24558#discussion_r1209657748


##########
infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoader.java:
##########
@@ -70,7 +80,17 @@ private Collection<T> load() {
     @SuppressWarnings("unchecked")
     public static <T> Collection<T> getServiceInstances(final Class<T> serviceInterface) {
         ShardingSphereServiceLoader<?> result = LOADERS.get(serviceInterface);
-        return (Collection<T>) (null != result ? result.getServiceInstances() : LOADERS.computeIfAbsent(serviceInterface, ShardingSphereServiceLoader::new).getServiceInstances());
+        if (null != result) {
+            return (Collection<T>) result.getServiceInstances();
+        }
+        synchronized (LOAD_LOCKS[serviceInterface.hashCode() % LOAD_LOCKS_COUNT]) {

Review Comment:
   Sorry, I missed this message before.
   
   `serviceInterface` might be synchronized here and in other places, I'm afraid there might be synchronization issue, so I use dedicated lock here.
   



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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