Spartez interview question

Concurrency problems with HashMap

Interview Answer

Anonymous

4 Jan 2019

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.