From df66482aa6ccbd270c1038e88ba6daf8810ea3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=88=E9=93=AD?= Date: Mon, 4 Mar 2024 09:55:18 +0800 Subject: [PATCH] fix #1380 --- .../rpc/registry/nacos/NacosRegistry.java | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/registry/registry-nacos/src/main/java/com/alipay/sofa/rpc/registry/nacos/NacosRegistry.java b/registry/registry-nacos/src/main/java/com/alipay/sofa/rpc/registry/nacos/NacosRegistry.java index 2396fa901..9c4d767dd 100644 --- a/registry/registry-nacos/src/main/java/com/alipay/sofa/rpc/registry/nacos/NacosRegistry.java +++ b/registry/registry-nacos/src/main/java/com/alipay/sofa/rpc/registry/nacos/NacosRegistry.java @@ -47,8 +47,6 @@ import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; import static com.alipay.sofa.rpc.common.utils.StringUtils.CONTEXT_SEP; @@ -103,8 +101,6 @@ public class NacosRegistry extends Registry { private Properties nacosConfig = new Properties(); - private static final Lock lock = new ReentrantLock(); - /** * Instantiates a new Nacos registry. * @@ -149,7 +145,6 @@ public synchronized void init() { nacosConfig.putAll(parameters); } - lock.lock(); try { if (providerObserver == null) { providerObserver = new NacosRegistryProviderObserver(); @@ -158,8 +153,6 @@ public synchronized void init() { namingService = NamingFactory.createNamingService(nacosConfig); } catch (NacosException e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_INIT_NACOS_NAMING_SERVICE, address), e); - } finally { - lock.unlock(); } } @@ -283,12 +276,7 @@ public List subscribe(final ConsumerConfig config) { try { ProviderInfoListener providerInfoListener = config.getProviderInfoListener(); - try { - lock.lock(); - providerObserver.addProviderListener(config, providerInfoListener); - } finally { - lock.unlock(); - } + providerObserver.addProviderListener(config, providerInfoListener); EventListener eventListener = event -> { if (event instanceof NamingEvent) { @@ -299,12 +287,7 @@ public List subscribe(final ConsumerConfig config) { instances = new ArrayList<>(); } instances.removeIf(i -> !i.isEnabled()); - try { - lock.lock(); - providerObserver.updateProviders(config, instances); - } finally { - lock.unlock(); - } + providerObserver.updateProviders(config, instances); } }; namingService.subscribe(serviceName, defaultCluster, eventListener); @@ -345,12 +328,7 @@ public void unSubscribe(ConsumerConfig config) { } } } - try { - lock.lock(); - providerObserver.removeProviderListener(config); - } finally { - lock.unlock(); - } + providerObserver.removeProviderListener(config); } }