Yes, it is true. HashMap.get() can cause an infinite loop. Everyone I've talked to didn't believe it either, but yet there it is -- right in front of my very eyes. Now, before anyone jumps up and shouts that HashMap isn't synchronized, I want to make it clear that I know that. In fact, here is the paragraph from the JavaDocs:
Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map.
Now, I've always taken that standard warning in all the Collections classes as simply stating the obvious: these data structures are synchronized and if you aren't doing your own synchronization you'll get dirty/unreliable/unknown data and/or behavior.
But never in my wildest dreams would I have thought that without proper synchronization that an infinite loop could occur!
Blogbody
Tuesday, July 26, 2005
Subscribe to:
Post Comments (Atom)
Popular Posts
- Yahoo! Mail: Revenge of the Oddpost
- MobileTracker - Cingular announces EDGE Wireless WAN service
- Linux Forum: Apache, Webmin and Mandrake - Linux Operating System Help
- Free AS400 & iSeries Software Tools & Utilities Downloads
- Common Gateway Interface (CGI) on the as400 / iSeries
- Table designs based on CSS and DIV elements
- The Laughing Boardroom video...a real world example!
- UDATE and *DATE in AS400 RPG
- IBM eServer iSeries - The Laughing Boardroom
- Does Anybody Care About AIX on the iSeries?
No comments:
Post a Comment