Here you can find the source of getInstanceCounter(String name)
Parameter | Description |
---|---|
name | proposed name of the instance. |
private static int getInstanceCounter(String name)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; public class Main { /**/*from w ww . j av a2 s . co m*/ * Internal storage for instance counters. */ private static ConcurrentMap<String, AtomicInteger> instanceCounters = new ConcurrentHashMap<String, AtomicInteger>(); /** * Returns a new counter for instance with core-name 'name'. We support multiple producers with same name by adding a minus <number> to the name, like Service, Service-1 etc. * @param name proposed name of the instance. * @return instance count for known instances with name 'name'. */ private static int getInstanceCounter(String name) { AtomicInteger counter = instanceCounters.get(name); if (counter != null) return counter.incrementAndGet(); counter = new AtomicInteger(0); AtomicInteger old = instanceCounters.putIfAbsent(name, counter); if (old != null) counter = old; return counter.incrementAndGet(); } }