Java – how to implement concurrent HashMap using the functions in LinkedHashMap?

I have used LinkedHashMap and accessorder true, and allow up to 500 entries to be used as LRU cache of data at any time However, due to scalability issues, I want to go to some thread - safe alternatives Concurrenthashmap seems good in this respect, but it lacks the functions of accessorder and removeeldestentry (map. Entry E) found in LinkedHashMap Anyone can point out some links or help me ease the implementation

Solution

I recently did something similar with concurrenthashmap < string, cacheentry >, in which cacheentry wraps the actual items and adds cache eviction statistics: expiration time, insertion time (FIFO / LIFO eviction), last use time (LRU / MRU eviction), number hit (for LFU / MFU eviction), etc The actual eviction is synchronized, and an ArrayList < cacheentry > is created and the appropriate comparator is used to execute collections Sort() to execute the eviction policy Since this is expensive, each eviction then gets rid of the bottom 5% of cacheentries I'm sure performance tuning will help

In your case, since you are executing FIFO, you can keep a concurrent linkedqueue separately When you add an object to the concurrenthashmap, execute the concurrentlinkedqueue. Command for the object add(). When you want to evict an entry, execute concurrentlinkedqueue Poll() to delete the oldest object, and then delete it from the concurrenthashmap

Update: other possibilities in this area include Java collections synchronization wrapper and Java 1.6 concurrent skiplistmap

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>