简体   繁体   中英

Different locks for a singleton class

I have a singleton class that contains 3 HashMap. Each hashmap acts like a pool. I put the unused entries in there. I encountered a concurrency modification exception so I was planning to implement synchronization on them. My problem is if I use the same lock for all of them, there would possibly be a performance issue. Because when I create an entry for that pool, it is through a web service call. Since I only need that each hashmap doesn't run concurrently, is it ok to create 3 object locks for them?

I recommend you to use ConcurrentHashMap .

The table is internally partitioned to try to permit the indicated number of concurrent updates without contention.

Try to tune performance with concurrencyLevel parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM