@Test public void testPutToConcurrentMap() throws Exception { final ConcurrentMap<String, AtomicInteger> hashMap = new ConcurrentHashMap<String, AtomicInteger>(); final CountDownLatch latch = new CountDownLatch(3); for (int i = 0; i < 3; i++) { Thread thread = new Thread(new Runnable() { @Override public void run() { for (int j = 0; j < 10000; j++) { AtomicInteger inter = CommonUtils.putToConcurrentMap(hashMap, "key", new AtomicInteger(0)); inter.incrementAndGet(); } latch.countDown(); } }); thread.start(); } latch.await(); Assert.assertEquals(hashMap.get("key").get(), 30000); }
public static <K, V> V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value) { V old = map.putIfAbsent(key, value); return old != null ? old : value; }
CommonUtils { public static <K, V> V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value) { V old = map.putIfAbsent(key, value); return old != null ? old : value; } }
CommonUtils { public static <K, V> V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value) { V old = map.putIfAbsent(key, value); return old != null ? old : value; }  }
CommonUtils { public static <K, V> V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value) { V old = map.putIfAbsent(key, value); return old != null ? old : value; }  static V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value); static boolean isTrue(String b); static boolean isTrue(Boolean b); static boolean isFalse(Boolean b); static boolean isFalse(String b); static boolean isEmpty(Collection collection); static boolean isNotEmpty(Collection collection); static boolean isEmpty(Map map); static boolean isNotEmpty(Map map); static boolean isEmpty(Object[] array); static boolean isNotEmpty(Object[] array); static T parseNum(T num, T defaultInt); static int parseInt(String num, int defaultInt); static long parseLong(String num, long defaultLong); static boolean parseBoolean(String bool, boolean defaultInt); static int[] parseInts(String nums, String sperator); static boolean listEquals(List<T> left, List<T> right); static String join(Collection collection, String separator); }
CommonUtils { public static <K, V> V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value) { V old = map.putIfAbsent(key, value); return old != null ? old : value; }  static V putToConcurrentMap(ConcurrentMap<K, V> map, K key, V value); static boolean isTrue(String b); static boolean isTrue(Boolean b); static boolean isFalse(Boolean b); static boolean isFalse(String b); static boolean isEmpty(Collection collection); static boolean isNotEmpty(Collection collection); static boolean isEmpty(Map map); static boolean isNotEmpty(Map map); static boolean isEmpty(Object[] array); static boolean isNotEmpty(Object[] array); static T parseNum(T num, T defaultInt); static int parseInt(String num, int defaultInt); static long parseLong(String num, long defaultLong); static boolean parseBoolean(String bool, boolean defaultInt); static int[] parseInts(String nums, String sperator); static boolean listEquals(List<T> left, List<T> right); static String join(Collection collection, String separator);  }