diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 5343e183637..2758760d39d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -48,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import static java.util.concurrent.Executors.newSingleThreadExecutor; @@ -99,7 +100,7 @@ public class RegistryProtocol implements Protocol { private final ProviderConfigurationListener providerConfigurationListener = new ProviderConfigurationListener(); //To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed. //providerurl <--> exporter - private final Map> bounds = new ConcurrentHashMap<>(); + private final ConcurrentMap> bounds = new ConcurrentHashMap<>(); private Cluster cluster; private Protocol protocol; private RegistryFactory registryFactory; @@ -212,19 +213,11 @@ private URL overrideUrlWithConfig(URL providerUrl, OverrideListener listener) { @SuppressWarnings("unchecked") private ExporterChangeableWrapper doLocalExport(final Invoker originInvoker, URL providerUrl) { String key = getCacheKey(originInvoker); - ExporterChangeableWrapper exporter = (ExporterChangeableWrapper) bounds.get(key); - if (exporter == null) { - synchronized (bounds) { - exporter = (ExporterChangeableWrapper) bounds.get(key); - if (exporter == null) { - final Invoker invokerDelegete = new InvokerDelegate(originInvoker, providerUrl); - exporter = new ExporterChangeableWrapper((Exporter) protocol.export(invokerDelegete), originInvoker); - bounds.put(key, exporter); - } - } - } - return exporter; + return (ExporterChangeableWrapper) bounds.computeIfAbsent(key, s -> { + Invoker invokerDelegete = new InvokerDelegate<>(originInvoker, providerUrl); + return new ExporterChangeableWrapper<>((Exporter) protocol.export(invokerDelegete), originInvoker); + }); } public void reExport(final Invoker originInvoker, URL newInvokerUrl) {