<?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/"
		>
<channel>
	<title>Comments for Blogbody</title>
	<atom:link href="http://lightbody.net/blog/?feed=comments-rss2" rel="self" type="application/rss+xml" />
	<link>http://lightbody.net/blog</link>
	<description>Patrick Lightbody&#039;s personal blog</description>
	<lastBuildDate>Tue, 17 Aug 2010 05:51:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>Comment on HashMap.get() can cause an infinite loop! by Henry B</title>
		<link>http://lightbody.net/blog/?p=307#comment-298</link>
		<dc:creator>Henry B</dc:creator>
		<pubDate>Tue, 17 Aug 2010 05:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2005/7/hashmapget_can_cause_an_infini.html#comment-298</guid>
		<description>Hey, I made a little simulation based on the author&#039;s explanation. He&#039;s right, infinite loop occurs when you are manipulating hashmap by a multiple threads or it could also happen on a web framework where multiple classes are accessing a component (session based) hasmap.

Yes it does consuming 100% CPU usage when you try to run it continously but not more than 5 times using Hashmap instance. But when I changed it to ConcurrentHashMap it works well. Hmmm..


import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author henry banzon
 * @version 1
 * @since 08/17/2010
 * @mailto: henry.banzon@pioneer.com.ph
 */

public class HashMapTest{
//  occurs 100% cpu usage
    Map map = new HashMap();

//  runs smoothly on this instance
//  Map map = new ConcurrentHashMap();


    public class HenryInner1  implements Runnable{
//      This thread does the inputs
        public void run() {
            for(int i = 1; i &lt; 1000; i++){
                System.out.println(&quot;HenryInner1 : &quot; + 1);
                if(i % 5 == 0) map.put(&quot;sample&quot; + i, null);
                else map.put(&quot;sample&quot; + i, &quot;value&quot; + i);
            }
        }
    }
    public class HenryInner2  implements Runnable{
//      This thread does the retrieval
        public void run() {
            for(int i = 1; i &lt; 1000; i++){
                System.out.println(&quot;HenryInner2 : &quot; + 1);
                System.out.println(map.get(&quot;sample&quot; + i));
                map.put(&quot;henry&quot; + i, &quot;banzon&quot; + i);
            }
        }
    }
    public class HenryInner3  implements Runnable{
//      This thread does the retrieval, removal and inputs
        public void run() {
            for(int i = 1; i &lt; 2000; i++){
                System.out.println(&quot;HenryInner3 : &quot; + 1);
                System.out.println(map.get(&quot;henry&quot; + i));
                System.out.println(map.remove(&quot;sample&quot; + i));
                map.put(&quot;sample&quot; + i, &quot;value&quot; + i);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        HashMapTest o = new HashMapTest();
        Thread thread1  = new Thread(o.new HenryInner1());
        Thread thread2  = new Thread(o.new HenryInner2());
        Thread thread3  = new Thread(o.new HenryInner3());
        thread1.start();

        Thread.sleep(5);
        thread2.start();

        Thread.sleep(5);
        thread3.start();
    }

}</description>
		<content:encoded><![CDATA[<p>Hey, I made a little simulation based on the author&#8217;s explanation. He&#8217;s right, infinite loop occurs when you are manipulating hashmap by a multiple threads or it could also happen on a web framework where multiple classes are accessing a component (session based) hasmap.</p>
<p>Yes it does consuming 100% <span class="caps">CPU </span>usage when you try to run it continously but not more than 5 times using Hashmap instance. But when I changed it to ConcurrentHashMap it works well. Hmmm..</p>
<p>import java.util.HashMap;<br />
import java.util.Map;<br />
import java.util.concurrent.ConcurrentHashMap;</p>
<p>/**<br />
 * @author henry banzon<br />
 * @version 1<br />
 * @since 08/17/2010<br />
 * @mailto: <a href="mailto:henry.banzon@pioneer.com.ph">henry.banzon@pioneer.com.ph</a><br />
 */</p>
<p>public class HashMapTest{<br />
//  occurs 100% cpu usage<br />
    Map map = new HashMap();</p>
<p>//  runs smoothly on this instance<br />
//  Map map = new ConcurrentHashMap();</p>
<p>    public class HenryInner1  implements Runnable{<br />
//      This thread does the inputs<br />
        public void run() {<br />
            for(int i = 1; i &lt; 1000; i++){<br />
                System.out.println(&#34;HenryInner1 : &#34; + 1);<br />
                if(i % 5 == 0) map.put(&#34;sample&#34; + i, null);<br />
                else map.put(&#34;sample&#34; + i, &#34;value&#34; + i);<br />
            }<br />
        }<br />
    }<br />
    public class HenryInner2  implements Runnable{<br />
//      This thread does the retrieval<br />
        public void run() {<br />
            for(int i = 1; i &lt; 1000; i++){<br />
                System.out.println(&#34;HenryInner2 : &#34; + 1);<br />
                System.out.println(map.get(&#34;sample&#34; + i));<br />
                map.put(&#34;henry&#34; + i, &#34;banzon&#34; + i);<br />
            }<br />
        }<br />
    }<br />
    public class HenryInner3  implements Runnable{<br />
//      This thread does the retrieval, removal and inputs<br />
        public void run() {<br />
            for(int i = 1; i &lt; 2000; i++){<br />
                System.out.println(&#34;HenryInner3 : &#34; + 1);<br />
                System.out.println(map.get(&#34;henry&#34; + i));<br />
                System.out.println(map.remove(&#34;sample&#34; + i));<br />
                map.put(&#34;sample&#34; + i, &#34;value&#34; + i);<br />
            }<br />
        }<br />
    }</p>
<p>    public static void main(String[] args) throws InterruptedException {<br />
        HashMapTest o = new HashMapTest();<br />
        Thread thread1  = new Thread(o.new <acronym title="">HenryInner1</acronym>);<br />
        Thread thread2  = new Thread(o.new <acronym title="">HenryInner2</acronym>);<br />
        Thread thread3  = new Thread(o.new <acronym title="">HenryInner3</acronym>);<br />
        thread1.start();</p>
<p>        Thread.sleep(5);<br />
        thread2.start();</p>
<p>        Thread.sleep(5);<br />
        thread3.start();<br />
    }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on HashMap.get() can cause an infinite loop! by Akku</title>
		<link>http://lightbody.net/blog/?p=307#comment-296</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-296</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>Comment on HashMap.get() can cause an infinite loop! by Laurence Vanhelsuwe</title>
		<link>http://lightbody.net/blog/?p=307#comment-295</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-295</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>Comment on Project Able: a complete Java web stack by Tutorial pantas project-able &#171; CASB Development Blog</title>
		<link>http://lightbody.net/blog/?p=378#comment-466</link>
		<dc:creator>Tutorial pantas project-able &#171; CASB Development Blog</dc:creator>
		<pubDate>Sun, 13 Sep 2009 03:10:59 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2006/8/project_able_a_complete_java_w.html#comment-466</guid>
		<description>[...] http://lightbody.net/blog/2006/08/project_able_a_complete_java_w.html [...] </description>
		<content:encoded><![CDATA[<p>[...] <a href="http://lightbody.net/blog/2006/08/project_able_a_complete_java_w.html" rel="nofollow">http://lightbody.net/blog/2006/08/project_able_a_complete_java_w.html</a> [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on HashMap.get() can cause an infinite loop! by Fred Roeber</title>
		<link>http://lightbody.net/blog/?p=307#comment-294</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-294</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>Comment on Moving multiple files in subversion by Marc</title>
		<link>http://lightbody.net/blog/?p=422#comment-511</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Tue, 18 Aug 2009 21:20:37 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2007/11/moving_multiple_files_in_subve.html#comment-511</guid>
		<description>404</description>
		<content:encoded><![CDATA[<p>404</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Added FriendFeed Widget: CSS problems persist by Aristote</title>
		<link>http://lightbody.net/blog/?p=473#comment-560</link>
		<dc:creator>Aristote</dc:creator>
		<pubDate>Wed, 12 Aug 2009 23:52:01 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/?p=473#comment-560</guid>
		<description>I dunno if you fix your problem but don&#039;t forget to add (at the correct place) &quot; !important &quot; at the end of each lines define friendfeed css.

For example : #friendfeed .bottom {background:none!important;}

But i agree with you, it&#039;s still difficult to custom this widget ...

You can also find advices over here :
http://groups.google.com/group/friendfeed/browse_thread/thread/0e63ed90af1cc018

http://learnbythedrop.com/drop/127</description>
		<content:encoded><![CDATA[<p>I dunno if you fix your problem but don&#8217;t forget to add (at the correct place) &#8221; !important &#8221; at the end of each lines define friendfeed css.</p>
<p>For example : #friendfeed .bottom {background:none!important;}</p>
<p>But i agree with you, it&#8217;s still difficult to custom this widget &#8230;</p>
<p>You can also find advices over here :<br />
<a href="http://groups.google.com/group/friendfeed/browse_thread/thread/0e63ed90af1cc018" rel="nofollow">http://groups.google.com/group/friendfeed/browse_thread/thread/0e63ed90af1cc018</a></p>
<p><a href="http://learnbythedrop.com/drop/127" rel="nofollow">http://learnbythedrop.com/drop/127</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on HashMap.get() can cause an infinite loop! by Ashish</title>
		<link>http://lightbody.net/blog/?p=307#comment-293</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-293</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>Comment on HashMap.get() can cause an infinite loop! by Alain RUSSIER</title>
		<link>http://lightbody.net/blog/?p=307#comment-292</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-292</guid>
		<description>Very clear and interesting</description>
		<content:encoded><![CDATA[<p>Very clear and interesting</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Twitter Said To Be Abandoning Ruby on Rails by StoreCrowd</title>
		<link>http://lightbody.net/blog/?p=430#comment-513</link>
		<dc:creator>StoreCrowd</dc:creator>
		<pubDate>Sat, 23 May 2009 10:10:05 +0000</pubDate>
		<guid isPermaLink="false">http://lightbody.net/blog/2008/5/twitter_said_to_be_abandoning.html#comment-513</guid>
		<description>Everything seems to be pretty stable for them now since they moved hosing away from Joyent &amp; applied the new Cache - Money (which is open source &amp; on github) :)</description>
		<content:encoded><![CDATA[<p>Everything seems to be pretty stable for them now since they moved hosing away from Joyent &amp; applied the new Cache &#8211; Money (which is open source &amp; on github) <img src='http://lightbody.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

