fingthinking commented on issue #1634: 
为什么要在AbstractMonitorFactory#getMonitor这个地方要用上锁
URL: 
https://github.com/apache/incubator-dubbo/issues/1634#issuecomment-383350164
 
 
   @chickenlj sorry,my English level is limited, What I am look at is tag 
"dubbo-2.5.4", donot have "Future" field, my solution like this:
   ```Java
   private static final Set<String> status = new ConcurrentHashSet<String>();
   public Monitor getMonitor(URL url) {
           url = 
url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY,
 MonitorService
                   .class.getName());
           String key = url.toServiceStringWithoutResolving();
           Monitor m = MONITORS.get(key);
           if (m != null) {
               return m;
           } else {
               // 自旋锁
               while (status.contains(key)){
                   try {
                       Thread.sleep(1);
                   } catch (InterruptedException ignored) {
                   }
               }
               status.add(key);
               try {
   
                   m = createMonitor(url);
                   if (m == null) {
                       throw new IllegalStateException("Can not create monitor 
" + url);
                   }
                   MONITORS.put(key, m);
                   return m;
               }finally {
                   status.remove(key);
               }
   
           }
       }
   ```
   whether or not it is correct?

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

Reply via email to