简体   繁体   中英

Java HashMap<String, String> containsKey() fails

I have a Java HashMap<String, String> . Firstly I populate this map with 100 known string keys. Next I use multiple callables to add random string keys, two thousand keys in total. I also use multiple callables to call HashMap.containsKey() for the 100 known keys. I execute these callables all concurrently, Why do I see many of these containsKey() calls fail? Surely String implements the hashCode() and equals() methods "properly".

What do I need to do to ensure my 100 known keys are always found within the map?

我所有的问题都可以通过简单地将HashMap()更改为ConcurrentHashMap()来解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM