use ConcurrentHashMap to replace Collections.synchronizedMap(HashMap) ?
Roger Riggs
roger.riggs at oracle.com
Wed Apr 20 19:09:09 UTC 2022
Hi,
There's usually a 'it depends' in questions like this.
ConcurrentHashMap *does NOT allow null *keys or values. HashMap *does
allow null* as keys and values.
And more obviously, using a synchronized HashMap does not allow any
concurrency.
ConcurrentHashMap is built to allow concurrent access.
Regards, Roger
On 20/04/2022 14:26, Xeno Amess wrote:
> Collections.synchronizedMap(new HashMap<Integer, byte[]>())
>
> new ConcurrentHashMap <Integer, byte[]> ()
>
> Is the later one always better than the first one?
>
> I personally think so, but are there any traps in it?
More information about the jdk-dev
mailing list