Java Utililty Methods ConcurrentMap

List of utility methods to do ConcurrentMap

Description

The list of methods to do ConcurrentMap are organized into topic(s).

Method

voidfileReaderDecrement(ConcurrentMap readers, Long fileNum)
file Reader Decrement
readers.compute(fileNum, (key, value) -> {
    if (value == null)
        throw new IllegalMonitorStateException("file not locked: " + fileNum);
    if (value.longValue() == 1L) {
        return null;
    } else {
        return value - 1L;
});
voidfileReaderIncrement(ConcurrentMap readers, Long fileNum)
file Reader Increment
readers.compute(fileNum, (key, value) -> value == null ? 1L : value + 1L);
Loggerget(Class clazz)
get
if (clazz == null) {
    return null;
Logger logger = loggers.get(clazz);
if (logger == null) {
    logger = LoggerFactory.getLogger(clazz);
    loggers.put(clazz, logger);
return logger;
ConcurrentMapgetCache(String cacheName)
get Cache
return MAP_OF_MAP.get(cacheName);
ConcurrentHashMapgetConcurrentMap(int... size)
get Concurrent Map
if (size.length == 0) {
    return new ConcurrentHashMap<K, V>();
} else {
    return new ConcurrentHashMap<K, V>(size[0]);
StringgetContextPath()
get Context Path
return (String) dataMap.get("__contextPath__");
MapgetFilesystem(String id)
get Filesystem
Map<String, String> fs = mounts.get(id);
if (fs == null) {
    fs = new ConcurrentHashMap<String, String>();
    Map<String, String> prev = mounts.putIfAbsent(id, fs);
    if (prev != null) {
        fs = prev;
return fs;
SetgetNestedSet(K1 key, ConcurrentMap> set)
Get and/or allocate as needed a nested concurrent set inside a concurrent map in a threadsafe way.
Set<K2> inner = set.get(key);
if (inner == null) {
    inner = Collections.newSetFromMap(new ConcurrentHashMap<K2, Boolean>());
    Set<K2> old = set.putIfAbsent(key, inner);
    if (old != null)
        inner = old;
return inner;
...
intgetNewLogFactor(String factorName)
get New Log Factor
Integer newFactor = null;
if (logFactorMap.containsKey(factorName)) {
    Integer oldFactor = logFactorMap.get(factorName);
    newFactor = oldFactor + 1;
    logFactorMap.put(factorName, newFactor);
} else {
    logFactorMap.put(factorName, 0);
    newFactor = 0;
...
TgetSingleInstance(Class classType)
get Single Instance
T instance = null;
if (instanceMap.containsKey(classType)) {
    instance = (T) instanceMap.get(classType);
} else {
    instance = classType.newInstance();
    instanceMap.put(classType, instance);
return instance;
...