简体   繁体   中英

java.lang.ArrayStoreException in java.util.Hashset

Here is the stack trace :

java.lang.ArrayStoreException
        at java.util.HashMap.transfer(Unknown Source)
        at java.util.HashMap.resize(Unknown Source)
        at java.util.HashMap.addEntry(Unknown Source)
        at java.util.HashMap.put(Unknown Source)
        at java.util.HashSet.add(Unknown Source)

Some observations :

  1. Its an intermittent issue
  2. JDK 1.6
  3. CentOS 5.3

As I understand this error is intermittent I suspect it occurs whenever the HashSet (hence underlying HashMap) needs to resize itself. But not sure why this ArrayStoreException . Now what I want to know is

-What are the scenarios wherein this error can occur ?

My guess is that you're trying to update the set from multiple threads concurrently. HashSet and HashMap aren't designed to be thread-safe - if you're going to access your set from multiple threads, you should use synchronization to prevent concurrent access.

That's just a guess, of course - without seeing your code I can't tell whether you are using multiple threads. It would go along with the intermittent side of things though...

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