<dependency>
<groupId>com.googlecode.concurrentlinkedhashmap</groupId>
<artifactId>concurrentlinkedhashmap-lru</artifactId>
<version>1.4.2</version>
</dependency>
ConcurrentMap<KeyType, ValueType> map = new ConcurrentLinkedHashMap.Builder<KeyType, ValueType>()
.initialCapacity(100)
.maximumWeightedCapacity(1000)
.concurrencyLevel(16)
.listener(new EvictionListener<KeyType, ValueType>() {
public void onEviction(KeyType key, ValueType value) {
}
})
.build();
map.put(key1, value1);
map.put(key2, value2);
ValueType value = map.get(key1);
map.remove(key2);
import java.util.concurrent.ConcurrentLinkedHashMap;
import java.util.concurrent.ConcurrentMap;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.EvictionListener;
public class ConcurrentLinkedHashMapExample {
public static void main(String[] args) {
ConcurrentMap<String, Integer> map = new ConcurrentLinkedHashMap.Builder<String, Integer>()
.initialCapacity(100)
.maximumWeightedCapacity(1000)
.concurrencyLevel(16)
.listener(new EvictionListener<String, Integer>() {
public void onEviction(String key, Integer value) {
System.out.println("Key: " + key + ", Value: " + value + " was evicted.");
}
})
.build();
map.put("A", 1);
map.put("B", 2);
map.put("C", 3);
map.put("D", 4);
System.out.println(map.get("A"));
System.out.println(map.get("B"));
System.out.println(map.get("C"));
System.out.println(map.get("D"));
}
}