You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/04/21 05:50:14 UTC

[GitHub] chickenlj commented on issue #1634: 为什么要在AbstractMonitorFactory#getMonitor这个地方要用上锁

chickenlj commented on issue #1634: 为什么要在AbstractMonitorFactory#getMonitor这个地方要用上锁
URL: https://github.com/apache/incubator-dubbo/issues/1634#issuecomment-383270026
 
 
   I think you should look at this `LOCK` as a whole, we have null check before entering this lock:
   ```java
   Monitor monitor = MONITORS.get(key);
           Future<Monitor> future = FUTURES.get(key);
           if (monitor != null || future != null) {
               return monitor;
           }
   
           LOCK.lock();
           try {
               monitor = MONITORS.get(key);
               future = FUTURES.get(key);
               if (monitor != null || future != null) {
                   return monitor;
               }
   
               final URL monitorUrl = url;
               final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl));
               listenableFutureTask.addListener(new MonitorListener(key));
               executor.execute(listenableFutureTask);
               FUTURES.put(key, listenableFutureTask);
   
               return null;
           } finally {
               // unlock
               LOCK.unlock();
           }
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services