Anonymous Asked in Cars &Transportation · 2 weeks ago

How do I make a HashMap thread-safe?

You can make HashMap thread safe by wrapping it with Collections.synchronizedMap() . 1 авг. 2013 г.


Is HashMap get thread-safe?

And, importantly, HashMap is not a thread-safe implementation, while Hashtable does provide thread-safety by synchronizing operations. Even though Hashtable is thread safe, it is not very efficient. Another fully synchronized Map, Collections.

How do you make a map thread-safe in Java?

If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable . If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable .

Which is known as thread-safe implementation of HashMap?

ConcurrentHashMap class is thread-safe i.e. multiple threads can operate on a single object without any complications. At a time any number of threads are applicable for a read operation without locking the ConcurrentHashMap object which is not there in HashMap.

How do I make sure a method is thread-safe?

There is no rule that makes the code thread safe, the only thing you can do is make sure that your code will work no matter how many times is it being actively executed, each thread can be interrupted at any point, with each thread being in its own state/location, and this for each function (static or otherwise) that ...

Related Questions

Relevance
Write us your question, the answer will be received in 24 hours