I need a card with the following requirements:
It must be very parallel. The put() , get() and remove() methods can be called simultaneously by multiple threads.
It must have a fixed size. If the HashMap size reaches the maximum value (for example, 10000), adding a new record to the card is not allowed. It CANNOT be an LRU cache, where the oldest entry is deleted when it reaches its maximum size.
ConcurrentHashMap may satisfy # 1. But I'm not sure how No. 2 can be implemented on top of ConcurrentHashMap without affecting concurrency (adding a custom put() method that will add a map only when the size is less than the maximum size should be "synchronized", which will lead to defeat the purpose of using a parallel HashMap ).
Please let me know your thoughts.
java multithreading concurrency java.util.concurrent concurrenthashmap
Arnab biswas
source share