com.xqbase.util.concurrent.CountMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xqbase-util-jdk17 Show documentation
Show all versions of xqbase-util-jdk17 Show documentation
Reusable Java components for www.xqbase.com
package com.xqbase.util.concurrent;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CountMap
extends ConcurrentHashMap {
private static final long serialVersionUID = 1L;
protected abstract V newCount();
public V acquire(K key) {
V count = get(key);
if (count == null) {
V newCount = newCount();
count = putIfAbsent(key, newCount);
if (count == null) {
return newCount;
}
}
count.incrementAndGet();
return count;
}
public void release(K key, V count) {
if (count.decrementAndGet() == 0) {
remove(key, Count.ZERO);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy