
com.venky.cache.UnboundedCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Commonly used programming tasks in java
The newest version!
package com.venky.cache;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
public abstract class UnboundedCache extends ConcurrentHashMap {
/**
*
*/
private static final long serialVersionUID = -279156550678934353L;
@SuppressWarnings("unchecked")
public V get(Object key){
K k = (K)key;
V v = super.get(k);
if (v == null){
v = getValue(k); //Wastful getValue is better than blocking GetValue.
if (v != null){
synchronized (this){
V vExisting = super.get(k);
if (vExisting == null){
super.put(k, v);
}else {
v = vExisting;
}
}
}
}
return v;
}
protected abstract V getValue(K key);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy