Is it necessary to synchronize a java HashMap file, if there is only one stream of letters

I keep in memory HashMap, which stores a list testUserIdsfor my own emailId.

HashMap<Integer, String> testUsers = new HashMap<>()

And there is only one background thread that reads additions / deletions to the list testUsersand performs operations on this map. Since there is only one thread on this card, I don’t have to make it a synchronized card.

But there are several streams on this map. Do I need ConcurrentHashMapif there is only one writer, but several readers?

+4
source share
2 answers

, ConcurrentHashMap ( Map ). , Map, Map, ConcurrentModificationException.

HashMap Javadoc:

, . - , , , .. p >

ConcurrentModificationException Javadoc:

java.util.ConcurrentModificationException

, , .

, , . undefined . Iterator ( , JRE) , . , , , , , .

+5

. , , .

0

Source: https://habr.com/ru/post/1660950/


All Articles