WHAT IS RACE CONDITION IN HASHMAP

lois waisbrooker

Total Post:70

Points:494
Posted by  lois waisbrooker
 1525  View(s)
Ratings:
Rate this:
Can anyone explain what is race condition in java hashmap
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: What is race condition in HashMap

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!