Atul More wrote:If the ConcurrentHashMap is static then how the locking will work is the only thing is in my mind.
ConcurrentHashMap is built for optimized access, both read and write. It doesn't lock the entire map but only segments. That doesn't prevent threads waiting on each other, but it does try to minimize it.
Even though the map is used for read the data not even for update or add.
If the map is really read-only, then you can consider not using any concurrent structure at all - an unmodifiable map may be a better fit, especially if you can create it at class initialization time. A simple HashMap is thread-safe as long as you're only doing reads. Wrap that using Collections.unmodifiableMap and you prevent writes completely.
In Java 8 and before, you can use a static initializer block (this is also what you can use if your contents are more dynamic, because you can use Java code to calculate keys and values):
In Java 9 and after you can use Map.of:
The latter can go up to 10 entries; after that you need to use the varargs method and Map.entry method: