You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "TeslaCN (via GitHub)" <gi...@apache.org> on 2023/04/11 04:51:31 UTC
[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24558: Avoid ConcurrentHashMap recursive update in ShardingSphereServiceLoader.getServiceInstances
TeslaCN commented on code in PR #24558:
URL: https://github.com/apache/shardingsphere/pull/24558#discussion_r1162298379
##########
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:
How about `synchronized (serviceInterface)`?
--
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