Sollicitatievraag bij Spartez

Concurrency problems with HashMap

Antwoord op sollicitatievraag

Anoniem

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.