Quantcast
Channel: Modifying hash map from a single thread and reading from multiple threads? - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Nicolas Filotto for Modifying hash map from a single thread and...

To be thread-safe, your code must synchronize any access to all shared mutable state. Here you share liveSocketsByDatacenter, an instance of HashMap a non thread-safe implementation of a Map that can...

View Article



Answer by Vishwanath Pattanshetti for Modifying hash map from a single thread...

Using ConcurrentHashMap should make your code threadsafe. Alternatively use synchronized methods to access existing hashmap.

View Article

Answer by clic for Modifying hash map from a single thread and reading from...

As you can read in detail e.g. here, if multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally to avoid an...

View Article

Answer by Krzysztof Cichocki for Modifying hash map from a single thread and...

It seems, that you can safely use ConcurrentHashMap here instead of regular HashMap and it should work.In your current approach, using regular HashMap, you need to have synchronization of...

View Article

Modifying hash map from a single thread and reading from multiple threads?

I have a class in which I am populating a map liveSocketsByDatacenter from a single background thread every 30 seconds and then I have a method getNextSocket which will be called by multiple reader...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images