<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		xmlns:media="http://search.yahoo.com/mrss"
		>
<channel>
	<title>Comments on: HashMap.get() can cause an infinite loop!</title>
	<atom:link href="http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/feed" rel="self" type="application/rss+xml" />
	<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html</link>
	<description>Patrick Lightbody's personal blog</description>
	<lastBuildDate>Sat, 05 Dec 2009 14:40:17 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Akku</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1300</link>
		<dc:creator>Akku</dc:creator>
		<pubDate>Mon, 16 Nov 2009 13:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1300</guid>
		<description>Rob,

Thanks for that article. We faced a similar situation in a job which spawned multiple threads, each of which were doing look-up in a HashMap for certain keys. If not found, the key-value was added in the Map for future lookup (Obviously, it should have been synchronized but it was not). Once in a while we would see the threads getting struck at the call to HashMap.get(). After analysing the code, we figured that making it a Hastable was obviously required but we were not sure this could be causing the threads to be struck. (Data consistency, ofcourse, we knew was compromised). Since the conversion to Hashtable, we have not observed the issue. This article helps explain a bit clearly what can lead to the infitine looping.</description>
		<content:encoded><![CDATA[<p>Rob,</p>
<p>Thanks for that article. We faced a similar situation in a job which spawned multiple threads, each of which were doing look-up in a HashMap for certain keys. If not found, the key-value was added in the Map for future lookup (Obviously, it should have been synchronized but it was not). Once in a while we would see the threads getting struck at the call to HashMap.get(). After analysing the code, we figured that making it a Hastable was obviously required but we were not sure this could be causing the threads to be struck. (Data consistency, ofcourse, we knew was compromised). Since the conversion to Hashtable, we have not observed the issue. This article helps explain a bit clearly what can lead to the infitine looping.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurence Vanhelsuwe</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1285</link>
		<dc:creator>Laurence Vanhelsuwe</dc:creator>
		<pubDate>Fri, 18 Sep 2009 13:20:12 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1285</guid>
		<description>CollectionSpy lets you see which of your HashMaps are accessed concurrently - ie are at risk of this infinite loop bug. As far as I know, it&#039;s the only Java tool that visualizes this information in an efficient and programmer-friendly manner. See www.collectionspy.com for more, including the free download page.</description>
		<content:encoded><![CDATA[<p>CollectionSpy lets you see which of your HashMaps are accessed concurrently &#8211; ie are at risk of this infinite loop bug. As far as I know, it&#8217;s the only Java tool that visualizes this information in an efficient and programmer-friendly manner. See <a href="http://www.collectionspy.com" rel="nofollow">http://www.collectionspy.com</a> for more, including the free download page.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred Roeber</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1280</link>
		<dc:creator>Fred Roeber</dc:creator>
		<pubDate>Sat, 05 Sep 2009 15:22:49 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1280</guid>
		<description>I just ran across this great thread on concurrency issues that&#039;s developed over a couple of years. I&#039;ve been doing concurrent applications for decades but am new to concurrent Java. I did come across an EXCELLENT presentation on the subject in the 200 page chapter on Concurrency in the 4th edition of Thinking in Java. Interestingly, Bruce Eckel (the author) said he got great help from Brian Goetz who chimed in on this thread above in 2005.

From my experience fixing threading problems in the OS code for VMS, Irix, SunOS and VxWorks, no matter how good you are you can never anticipate all the ways threaded code will break. With increasingly complex and common multicore machines, this becomes more true. When documentation says &quot;must&quot; take it as gospel.

This thread was a great read!</description>
		<content:encoded><![CDATA[<p>I just ran across this great thread on concurrency issues that&#8217;s developed over a couple of years. I&#8217;ve been doing concurrent applications for decades but am new to concurrent Java. I did come across an <span class="caps">EXCELLENT </span>presentation on the subject in the 200 page chapter on Concurrency in the 4th edition of Thinking in Java. Interestingly, Bruce Eckel (the author) said he got great help from Brian Goetz who chimed in on this thread above in 2005.</p>
<p>From my experience fixing threading problems in the OS code for <span class="caps">VMS,</span> Irix, SunOS and VxWorks, no matter how good you are you can never anticipate all the ways threaded code will break. With increasingly complex and common multicore machines, this becomes more true. When documentation says &#8220;must&#8221; take it as gospel.</p>
<p>This thread was a great read!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashish</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1262</link>
		<dc:creator>Ashish</dc:creator>
		<pubDate>Fri, 24 Jul 2009 14:38:31 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1262</guid>
		<description>Thanks for the wonderful explainations.... Our application will go into infinite loop and have to restrt the server to get it work. so now using ConcurrentHashMap which solves this problem atleast... I wish i was able to nail down this issue few months back then wouldnt had suffer more... lol

Thanks,
Ashish</description>
		<content:encoded><![CDATA[<p>Thanks for the wonderful explainations&#8230;. Our application will go into infinite loop and have to restrt the server to get it work. so now using ConcurrentHashMap which solves this problem atleast&#8230; I wish i was able to nail down this issue few months back then wouldnt had suffer more&#8230; lol</p>
<p>Thanks,<br />
Ashish</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alain RUSSIER</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1258</link>
		<dc:creator>Alain RUSSIER</dc:creator>
		<pubDate>Thu, 04 Jun 2009 08:03:30 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1258</guid>
		<description>Very clear and interesting</description>
		<content:encoded><![CDATA[<p>Very clear and interesting</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Concurrency and HashMap</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1221</link>
		<dc:creator>Concurrency and HashMap</dc:creator>
		<pubDate>Fri, 30 Jan 2009 05:55:31 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1221</guid>
		<description>[...] Finally i will leave you with this interesting bug in Java which says HashMap can get into infinite loop when used in muti Threaded Environment which further reiterates my point that not all the possible scenarios can be visualized in a multi threaded environment and therefore one should rely on basics rather than trying a smart creativity which has high probability of landing into trouble at some point in future. You can read details about the infinite loop problem here. [...]</description>
		<content:encoded><![CDATA[<p>[...] Finally i will leave you with this interesting bug in Java which says HashMap can get into infinite loop when used in muti Threaded Environment which further reiterates my point that not all the possible scenarios can be visualized in a multi threaded environment and therefore one should rely on basics rather than trying a smart creativity which has high probability of landing into trouble at some point in future. You can read details about the infinite loop problem here. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: metatech</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1076</link>
		<dc:creator>metatech</dc:creator>
		<pubDate>Mon, 01 Dec 2008 13:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1076</guid>
		<description>Here is an example stack trace for those like who search Google with it.

&quot;TP-Processor33&quot; daemon prio=10 tid=0x02591798 nid=0x208 runnable
[0x5ef79000..0x5ef7fa70]
    at java.util.LinkedHashMap.transfer(LinkedHashMap.java:231)
    at java.util.HashMap.resize(HashMap.java:509)
    at java.util.LinkedHashMap.addEntry(LinkedHashMap.java:406)
    at java.util.HashMap.put(HashMap.java:431) 

I suppose the same can happen for HashMap.transfer or any other flavour.</description>
		<content:encoded><![CDATA[<p>Here is an example stack trace for those like who search Google with it.</p>
<p>&#8220;TP-Processor33&#8243; daemon prio=10 tid=0&#215;02591798 nid=0&#215;208 runnable<br />
[0x5ef79000..0&#215;5ef7fa70]<br />
    at java.util.LinkedHashMap.transfer(LinkedHashMap.java:231)<br />
    at java.util.HashMap.resize(HashMap.java:509)<br />
    at java.util.LinkedHashMap.addEntry(LinkedHashMap.java:406)<br />
    at java.util.HashMap.put(HashMap.java:431) </p>
<p>I suppose the same can happen for HashMap.transfer or any other flavour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Egge</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-1028</link>
		<dc:creator>Brian Egge</dc:creator>
		<pubDate>Fri, 03 Oct 2008 02:25:34 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-1028</guid>
		<description>A similar, but no less fun, loop can occur within DateFormat.  Concurrent use generally leads to garbage in your formatted dates, but can upon occasion cause the DateFormat to get caught in a loop.  

If multiple threads access a formatter concurrently, it must be synchronized externally.

I feel the &#039;must&#039; in the JavaDoc is a pretty good warning to say your worst nightmares may come true if you break the rule.  Because the implementation of a class is allowed to change, the JavaDoc shouldn&#039;t have to specify exactly what the worst case scenario is.  In fact, if you haven&#039;t designed a class with concurrency in mind, it can be really hard to anticipate what the worst case scenario is.</description>
		<content:encoded><![CDATA[<p>A similar, but no less fun, loop can occur within DateFormat.  Concurrent use generally leads to garbage in your formatted dates, but can upon occasion cause the DateFormat to get caught in a loop.  </p>
<p>If multiple threads access a formatter concurrently, it must be synchronized externally.</p>
<p>I feel the &#8216;must&#8217; in the JavaDoc is a pretty good warning to say your worst nightmares may come true if you break the rule.  Because the implementation of a class is allowed to change, the JavaDoc shouldn&#8217;t have to specify exactly what the worst case scenario is.  In fact, if you haven&#8217;t designed a class with concurrency in mind, it can be really hard to anticipate what the worst case scenario is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark L</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-969</link>
		<dc:creator>Mark L</dc:creator>
		<pubDate>Fri, 29 Aug 2008 20:41:57 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-969</guid>
		<description>I did convert to ConcurrentHashMap which is in new java.util.concurrent collections. I performed a few tests to check for memory and performance differences of both HashMap and ConcurrentHashMap  and they appeared to me to perform roughly about the same. 

ConcurrentHashMap sure has solved my problem with this.

Thanks for your original post all them years ago Patrick.</description>
		<content:encoded><![CDATA[<p>I did convert to ConcurrentHashMap which is in new java.util.concurrent collections. I performed a few tests to check for memory and performance differences of both HashMap and ConcurrentHashMap  and they appeared to me to perform roughly about the same. </p>
<p>ConcurrentHashMap sure has solved my problem with this.</p>
<p>Thanks for your original post all them years ago Patrick.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: plightbo</title>
		<link>http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html/comment-page-1#comment-967</link>
		<dc:creator>plightbo</dc:creator>
		<pubDate>Fri, 29 Aug 2008 14:58:02 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-967</guid>
		<description>Maninder,
You&#039;ll have to synchronize it. It shouldn&#039;t really cause much of a hit, so just go for it. Or, use the new java.util.concurrent collections and they&#039;ll manage it for you. Good luck!</description>
		<content:encoded><![CDATA[<p>Maninder,<br />
You&#8217;ll have to synchronize it. It shouldn&#8217;t really cause much of a hit, so just go for it. Or, use the new java.util.concurrent collections and they&#8217;ll manage it for you. Good luck!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
