---
title: "What is race condition in HashMap"  
description: "What is race condition in HashMap"  
author: "Anonymous User"  
published: 2015-09-02  
updated: 2015-09-02  
canonical: https://www.mindstick.com/forum/33432/what-is-race-condition-in-hashmap  
category: "java"  
tags: ["java", "collection"]  
reading_time: 1 minute  

---

# What is race condition in HashMap

Can [anyone explain](https://www.mindstick.com/forum/34220/can-anyone-explain-me-about-off-page-activity) what is [race condition](https://www.mindstick.com/forum/161213/what-is-a-race-condition-and-how-can-it-be-avoided) in [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) [hashmap](https://www.mindstick.com/forum/159211/what-are-the-differences-between-a-hashmap-and-a-hashtable-in-java)

## Replies

### Reply by Anonymous User

[Race](https://yourviews.mindstick.com/view/81397/will-uk-win-corona-vaccine-human-trial-race) conditions in Java are always tricky to find and solve. Not many people know about it that hashmap could run into race [condition](https://www.mindstick.com/forum/12711/select-query-with-and-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.


---

Original Source: https://www.mindstick.com/forum/33432/what-is-race-condition-in-hashmap

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
