Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java HashMap sometimes returning wrong value in some threads

davidthi808-JavaNetFeb 22 2012 — edited Nov 4 2012
We are not using one HashMap across threads (yes that is bad for many reasons). Each thread has its own HashMap.

We have a class that extends from Thread. In Thread.run() we create a HashMap, set a key/value pair in it, and pass that HashMap to a method. That method retrieves the value from the HashMap, inserts it into a string, and returns the string.

Sometimes the returned string has a different value (still in Thread.run()). This only occurs on hardware with 3+ physical cores. And it has only happened twice (before we added logging to help us find exactly what is going on of course).

Any idea why this would occur.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2012
Added on Feb 22 2012
5 comments
1,279 views