Which Map to be used in Java for huge concurrent operation in web service like 100 hit per second. Performance also in consideration.
-
yes as @LukeLee suggested 100 isn't huge. if there are no duplicates consider using treemap. – Abhishek Oct 25 '16 at 05:59
-
around 300 update needed at map per/sec, so for that also treemap is fine? – salman admission Oct 25 '16 at 06:50
-
How many items in your map ? do you add/remove a lot or do yyou mainly find items ? – Asoub Oct 25 '16 at 07:18
3 Answers
java.util.concurrent.ConcurrentHashMap should do the job.
- it is thread safe without synchronizing the whole map
- reads can happen very fast while write is done with a lock
- there is no locking at the object level.
If you plan to process a huge amount of data, you can take a look at this question for more informations.
-
around 300 update needed at map per/sec, so for that also ConcurrentHashMap is fine – salman admission Oct 25 '16 at 06:51
-
yes,100 is not huge.Huge concurrent operation u should use ConcurrentHashMap and learn more about current package.

- 1
- 1
-
around 300 update needed at map per/sec, so for that also ConcurrentHashMap is fine? – salman admission Oct 25 '16 at 06:51
For such load, you can either go for ConcurrentHashMap or SynchronizedMap.
But I would say if you look from a scalability perspective (If the loads can increase in the future), I would recommend to use a ConcurrentHashMap.
And also in ConcurrentHashMap, the locking is not on the entire map level. Instead it is at the block level (block can be single key or a set of keys).
Please refer http://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html for more information on ConcurrentHashMap internal working.

- 960
- 12
- 15