0

Which Map to be used in Java for huge concurrent operation in web service like 100 hit per second. Performance also in consideration.

3 Answers3

0

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.

Community
  • 1
  • 1
Dryr
  • 113
  • 7
0

yes,100 is not huge.Huge concurrent operation u should use ConcurrentHashMap and learn more about current package.

Madman
  • 1
  • 1
0

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.

FatherMathew
  • 960
  • 12
  • 15