Class ClockMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
org.apache.cayenne.util.ClockMap<K,V>
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>

public class ClockMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>
A bounded concurrent map that evicts the entries least recently read. It is a ConcurrentHashMap with the CLOCK ("second chance") replacement policy on top: each entry carries a "referenced" bit that a read sets, and once the map outgrows its maximum size, a sweep walks the entries, clearing the bit of those that were read since its last pass and removing those that were not. The policy approximates LRU, with a read costing one hash lookup and, at most once per sweep revolution, one bit write: no allocation, no queue and no linked list is touched on a read.

The sweep runs on the thread that inserts past the limit and is budgeted, so that no single insert pays for a whole revolution. The map may therefore briefly hold a few entries more than its maximum size. A single sweep runs at a time; inserts that find it running skip it, and the next insert catches up.

Iteration views are weakly consistent, like those of ConcurrentHashMap, and do not count as reads.

Since:
5.0