You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/11/01 14:28:47 UTC

[GitHub] xiangwangcheng commented on issue #515: org.apache.rocketmq.common.stats.StatsItemSet#getAndCreateStatsItem has multi-thread problem

xiangwangcheng commented on issue #515: org.apache.rocketmq.common.stats.StatsItemSet#getAndCreateStatsItem has multi-thread problem
URL: https://github.com/apache/rocketmq/issues/515#issuecomment-435057848
 
 
   Use putIfAbsent will solve this problem.
   
   ```
   public StatsItem getAndCreateStatsItem(final String statsKey) {
       StatsItem statsItem = this.statsItemTable.get(statsKey);
       if (null == statsItem) {
           statsItem = new StatsItem(this.statsName, statsKey, this.scheduledExecutorService, this.log);
           StatsItem prev = this.statsItemTable.putIfAbsent(statsKey, statsItem);
   
           if (null != prev) {
               statsItem = prev;
               // statsItem.init();
           }
       }
   
       return statsItem;
   }
   ```

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