Home > DeveloperSection > Forums > What is race condition in HashMap
lois waisbrooker
lois waisbrooker

Total Post:70

Posted on    September-02-2015 12:54 AM

 Java Java  Collection 

 1 Reply(s)
 467  View(s)
Rate this:
Can anyone explain what is race condition in java hashmap

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    September-02-2015 6:53 AM

Race conditions in Java are always tricky to find and solve. Not many people know about it that hashmap could run into race condition if it would be modified by two threads simultaneous and one thread tries to re-siz or rehash the map because of capacity crossing threshold value. Since hashmap maintains a linked list of element in bucket and while copying from one hashmap to other or old to new order of linked list got reversed, which could result in infinite loop if two threads are doing resizing at same time?

Otherwise some set e.g. TreeSet and TreeMap which uses compareTo will not able to detect duplicates and allow duplicate inside set.

Don't want to miss updates? Please click the below button!

Follow MindStick