ConcurrentHashMap的使用
http://blog.csdn.net/gjt19910817/article/details/47353909
- Long oldValue, newValue;
- while(true) {
- oldValue = wordCounts.get(word);
- if(oldValue == null) {
- // Add the word firstly, initial the value as 1
- newValue = 1L;
- if(wordCounts.putIfAbsent(word, newValue) == null) {
- break;
- }
- }else{
- newValue = oldValue + 1;
- if(wordCounts.replace(word, oldValue, newValue)) {
- break;
- }
- }
- }