com.firefly.utils.collection.SoftReferenceConcurrentHashMap Maven / Gradle / Ivy
package com.firefly.utils.collection;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
public class SoftReferenceConcurrentHashMap extends AbstractConcurrentAutomaticClearMap {
private class ValueSoftReference extends SoftReference {
K key;
public ValueSoftReference(K key, V value) {
super(value, refQueue);
this.key = key;
}
}
@SuppressWarnings("unchecked")
@Override
protected void clearInvalidEntry(Reference extends V> ref) {
map.remove(((ValueSoftReference) ref).key);
}
@Override
protected Reference createRefence(K key, V value) {
return new ValueSoftReference(key, value);
}
}