ConcurrentHashMap的使用

http://blog.csdn.net/gjt19910817/article/details/47353909

  1. Long oldValue, newValue;  
  2.     while(true) {  
  3.         oldValue = wordCounts.get(word);  
  4.         if(oldValue == null) {  
  5.             // Add the word firstly, initial the value as 1  
  6.             newValue = 1L;  
  7.             if(wordCounts.putIfAbsent(word, newValue) == null) {  
  8.                 break;  
  9.             }  
  10.         }else{  
  11.             newValue = oldValue + 1;  
  12.             if(wordCounts.replace(word, oldValue, newValue)) {  
  13.                 break;  
  14.             }  
  15.         }  
  16.     }  
原文地址:https://www.cnblogs.com/ydxblog/p/7886214.html