zonghaishang closed pull request #2566: Update AbstractRegistryFactory.java
URL: https://github.com/apache/incubator-dubbo/pull/2566
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index 4c83ea315f..a4db4f96b4 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -85,24 +85,31 @@ public Registry getRegistry(URL url) {
url = url.setPath(RegistryService.class.getName())
.addParameter(Constants.INTERFACE_KEY,
RegistryService.class.getName())
.removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
+
String key = url.toServiceString();
- // Lock the registry access process to ensure a single instance of the
registry
- LOCK.lock();
- try {
- Registry registry = REGISTRIES.get(key);
- if (registry != null) {
- return registry;
- }
- registry = createRegistry(url);
- if (registry == null) {
- throw new IllegalStateException("Can not create registry " +
url);
+
+ Registry registry = REGISTRIES.get(key);
+
+ if (registry == null){
+
+ //阻塞创建相同的注册服务
+ synchronized (key){
+
+ if (registry == null){
+
+ registry = createRegistry(url) ;
+
+ if (registry == null) {
+ throw new IllegalStateException("Can not create
registry " + url);
+ }
+
+ REGISTRIES.put(key, registry) ;
+ }
}
- REGISTRIES.put(key, registry);
- return registry;
- } finally {
- // Release the lock
- LOCK.unlock();
}
+
+
+ return registry ;
}
protected abstract Registry createRegistry(URL url);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services