I am developing the custom i18N library. in that, I have developed one function for getting locale object as per as input country and language.
I don't want to initialize locale object for every request. Can I use
Assuming that you use a version of Java older than 8, if you want to maximize the concurrency level of a
ConcurrentHashMap, you need to:
ConcurrentHashMapwith the constructor
ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)in order to set the
concurrencyLevelcorresponding to the total amount of segments to use knowing that by default it is 16 and choose it wisely as using a significantly higher value than what you need can waste space and time, and a significantly lower value can lead to thread contention.
hashCode()of your key properly in order to distribute your entries the best you can over the different segments.
In Java 8, the implementation of an
ConcurrentHashMap has completely been reviewed such that you don't have segments anymore, the
concurrencyLevel is now used as a sizing hint nothing more so #1 is no more really needed but #2 is still a good practice.