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 class CountMap extends ConcurrentHashMap {
private static final long serialVersionUID = 1L;
protected Count newCount() {
return new Count();
}
public Count acquire(K key) {
Count count = get(key);
if (count == null) {
Count newCount = newCount();
count = putIfAbsent(key, newCount);
if (count == null) {
count = newCount;
}
}
count.incrementAndGet();
return count;
}
public void release(K key, Count count) {
if (count.decrementAndGet() == 0) {
remove(key, Count.ZERO);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy