Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronizing LinkedHashmap externally

What is the best way to implement synchronization of a linkedhashmap externally, without using Collections.synchronizedMap

When Collections.synchronizedMap is used entire datastructure is locked, so performance is hugely impacted in a bad way.

What is the best way to lock only required part of datastructure. e.g. If thread is accessing key (K1), it should lock only Key(K1) and Value(v1) part of the datastructure

like image 864
user462455 Avatar asked Dec 23 '12 23:12

user462455


1 Answers

You can't get a fine-grained-locking, FIFO-eviction concurrent map from the built-in Java implementations.

Check out Guava's Cache or the open-source ConcurrentLinkedHashMap project.

like image 145
Louis Wasserman Avatar answered Sep 22 '22 06:09

Louis Wasserman