I would use ConcurrentSkipListMapand repeat the card periodically to clear expired items. Since the skipist is unlimited, this opens up the possibility of memory when the eviction thread cannot catch up, but in practice it seems very, very unlikely if you are not doing something extreme. I did something similar too, when I did not do this want to use a background thread:
static AtomicInteger cnt = new AtomicInteger();
Val put(K key, V val){
if(cnt.getAndIncrement() % 100 == 0){
}
}
if(cnt.getAndIncrement() % 100 == 0), , " ", , , , b.
, , ... , :
class Entity implaments Comparable<Entity>{
static AtomicInteger SEQ = new AtomicInteger();
int id = SEQ.getAndIncrement();
long timeStamp = System.currentTimeMillis();
int compareTo(Entity other){
}