Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What happens if two threads perform a get of one hashmap at the same time?

0
Posted

What happens if two threads perform a get of one hashmap at the same time?

0

Location: http://www.jguru.com/faq/view.jsp?EID=1048741 Created: Jan 21, 2003 Author: Muruganantham Mani (http://www.jguru.com/guru/viewbio.jsp?EID=1041080) Question originally posed by Enrique Monton (http://www.jguru.com/guru/viewbio.jsp?EID=755656 [I know a HashMap object is not synchronized if not done explicitly, so in a case where you have to write and read data in a hashmap from different threads you need to synchronize it (or use another object). However in my case I am writing to the HashMap (put) only once and it is done at the beginnig. Once the HashMap is filled I am going to read it from different threads at the same time. Do I need to synchronize these reads?] Synchronization needs to be done only when there is a chance of changing the data from different threads simultaneously. In your case, it is simply going to be a read, the synchronization is not required. If you need to remove or modify the values in the hashmap, then you [may] need to synchronize that. For synchron

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123