I have a Hashmap that, for speed reasons, I would like to not require locking on. Will updating it and accessing it at the same time cause any issues, assuming I don\'t min
Yes. Very Bad Things will happen. For example, your thread might get stuck in an infinite loop.
Either use ConcurrentHashMap, or NonBlockingHashMap
Yes, it will cause major problems. One example is what could happen when adding a value to the hash map: this can cause a rehash of the table, and if that occurs while another thread is iterating over a collision list (a hash table "bucket"), that thread could erroneously fail to find a key that exists in the map. HashMap
is explicitly unsafe for concurrent use.
Use ConcurrentHashMap instead.
I read here or elsewhere, no, you don't access from multi thread, but noone says what's really happen.
So, I seen today (that's why I'm on this - old - question) on a application running in production since March : 2 put on the same HashSet (then HashMap) cause a CPU overload (near 100%), and memory increasing of 3GB, then down by GC. We have to restart the app.