<?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 on: Immutable Data Structures in Concurrent Java Applications</title>
	<atom:link href="http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/</link>
	<description>Object Partners Inc.</description>
	<lastBuildDate>Tue, 31 Jan 2012 16:52:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Weekly Link Post Template &#171; Rhonda Tipton&#8217;s WebLog</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-432</link>
		<dc:creator>Weekly Link Post Template &#171; Rhonda Tipton&#8217;s WebLog</dc:creator>
		<pubDate>Mon, 08 Feb 2010 03:07:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-432</guid>
		<description>[...] Immutable Data Structures in Concurrent Java Applications &#8211; You can minimize synchronization and the headaches that go with it using immutable data structures. [...]</description>
		<content:encoded><![CDATA[<p>[...] Immutable Data Structures in Concurrent Java Applications &#8211; You can minimize synchronization and the headaches that go with it using immutable data structures. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ruben</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-431</link>
		<dc:creator>ruben</dc:creator>
		<pubDate>Fri, 05 Feb 2010 11:12:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-431</guid>
		<description>Hi,

Two things:

1) If Contact is stored in a Map, please override equals() &amp; hashCode().

2) Collections.EMPTY_MAP is already immutable, no need to re-wrap it in the constructor.

Cheers.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Two things:</p>
<p>1) If Contact is stored in a Map, please override equals() &amp; hashCode().</p>
<p>2) Collections.EMPTY_MAP is already immutable, no need to re-wrap it in the constructor.</p>
<p>Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bubak</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-429</link>
		<dc:creator>bubak</dc:creator>
		<pubDate>Wed, 03 Feb 2010 13:34:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-429</guid>
		<description>Scala and case classes makes it way easier.</description>
		<content:encoded><![CDATA[<p>Scala and case classes makes it way easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitris Andreou</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-428</link>
		<dc:creator>Dimitris Andreou</dc:creator>
		<pubDate>Wed, 03 Feb 2010 09:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-428</guid>
		<description>Such structures are called &quot;persistent&quot;, or fully persistent in this case since every version of the structure can be used to create a new version. Hash tables (or even array-based lists) are particularly bad examples of such, since they incur excessive computational cost. 

A much better example of such a structures would be a tree-based map (a balanced tree in particular would only incur O(log(n)) node copies instead of O(n) of hash table).

Still, if the persistent map above is merely to used to avoid synchronization issues, and not to be able to access historical versions of a structure, then it is unnecessarily wasteful. Assuming you need a Map with the ability to capture proper snapshots, so CHM is out: if a Map is shared, fine, make that immutable. If any thread needs to update that shared instance, sure, protect it with a lock or so. But if a thread wants to access the map, and then modify it locally (in your example, by calling getContacts() and then immutablePut etc), it is much more efficient to copy the map *once* (using the immutable Map from contacts) into a regular (&quot;ephemeral&quot;) HashMap for further updates - no need to continuously copy a thread-local value if you don&#039;t need the persistency.

Dimitris</description>
		<content:encoded><![CDATA[<p>Such structures are called &#8220;persistent&#8221;, or fully persistent in this case since every version of the structure can be used to create a new version. Hash tables (or even array-based lists) are particularly bad examples of such, since they incur excessive computational cost. </p>
<p>A much better example of such a structures would be a tree-based map (a balanced tree in particular would only incur O(log(n)) node copies instead of O(n) of hash table).</p>
<p>Still, if the persistent map above is merely to used to avoid synchronization issues, and not to be able to access historical versions of a structure, then it is unnecessarily wasteful. Assuming you need a Map with the ability to capture proper snapshots, so CHM is out: if a Map is shared, fine, make that immutable. If any thread needs to update that shared instance, sure, protect it with a lock or so. But if a thread wants to access the map, and then modify it locally (in your example, by calling getContacts() and then immutablePut etc), it is much more efficient to copy the map *once* (using the immutable Map from contacts) into a regular (&#8220;ephemeral&#8221;) HashMap for further updates &#8211; no need to continuously copy a thread-local value if you don&#8217;t need the persistency.</p>
<p>Dimitris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-427</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Wed, 03 Feb 2010 07:13:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-427</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Twitter by fshehadeh: RT: @objectpartners: From the Blog: Immutable Data Structures in Concurrent Java Applications http://ow.ly/16tjYL...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post&#8230;</strong></p>
<p>This post was mentioned on Twitter by fshehadeh: RT: @objectpartners: From the Blog: Immutable Data Structures in Concurrent Java Applications <a href="http://ow.ly/16tjYL.." rel="nofollow">http://ow.ly/16tjYL..</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Heinz Kabutz</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-426</link>
		<dc:creator>Heinz Kabutz</dc:creator>
		<pubDate>Tue, 02 Feb 2010 22:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-426</guid>
		<description>Fantastic article, Jim!

Immutability certainly makes things much easier.

Some weird effects happen when we modify the state of keys in collections - they tend to disappear completely, together with their values, only to reappear later when the map is rehashed.  Depends on the map implementation of course.

We probably also need an atomic &quot;replace&quot; method that removes the old contact and puts in a new one (also immutable).  Otherwise there would be no way to change your email address.

Keep up the articles, I&#039;m looking forward to the next one!

Heinz</description>
		<content:encoded><![CDATA[<p>Fantastic article, Jim!</p>
<p>Immutability certainly makes things much easier.</p>
<p>Some weird effects happen when we modify the state of keys in collections &#8211; they tend to disappear completely, together with their values, only to reappear later when the map is rehashed.  Depends on the map implementation of course.</p>
<p>We probably also need an atomic &#8220;replace&#8221; method that removes the old contact and puts in a new one (also immutable).  Otherwise there would be no way to change your email address.</p>
<p>Keep up the articles, I&#8217;m looking forward to the next one!</p>
<p>Heinz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmcclure</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-419</link>
		<dc:creator>jmcclure</dc:creator>
		<pubDate>Tue, 02 Feb 2010 16:29:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-419</guid>
		<description>Dean,

You are correct in that there is some performance overhead. This is just a shallow copy however so its not a big impact unless either the map is huge or it is updated often. The overhead is outweighed by the safety of the methodology. This is a common paradigm in functional programming that is starting to make its way into OOP due in no small part to the creation of Scala.

Ultimately you are correct in that you should always weigh the costs of different implementations. I&#039;m not intending to imply that you should always use immutable data structures. Only to present another tool for your development toolbox.</description>
		<content:encoded><![CDATA[<p>Dean,</p>
<p>You are correct in that there is some performance overhead. This is just a shallow copy however so its not a big impact unless either the map is huge or it is updated often. The overhead is outweighed by the safety of the methodology. This is a common paradigm in functional programming that is starting to make its way into OOP due in no small part to the creation of Scala.</p>
<p>Ultimately you are correct in that you should always weigh the costs of different implementations. I&#8217;m not intending to imply that you should always use immutable data structures. Only to present another tool for your development toolbox.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Andreasen</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-418</link>
		<dc:creator>Dave Andreasen</dc:creator>
		<pubDate>Tue, 02 Feb 2010 16:23:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-418</guid>
		<description>Great article.  I like copy approach for handling the updates to the set of contacts.  I have used other synchronization approaches in the past and they have been fragile for the reasons you have outlined above.</description>
		<content:encoded><![CDATA[<p>Great article.  I like copy approach for handling the updates to the set of contacts.  I have used other synchronization approaches in the past and they have been fragile for the reasons you have outlined above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dean</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-417</link>
		<dc:creator>Dean</dc:creator>
		<pubDate>Tue, 02 Feb 2010 15:47:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-417</guid>
		<description>Jim,

I like the idea of using immutable data structures for simple classes, but for a collection this could incur a pretty large performance hit.  Compare the performance of immutablePut() to this:

    synchronized(contactMap) {
        sendMessages(Map contactMap);
    }

When taking over someone else&#039;s code I like to take inventory of where in the code shared, mutable state exists.  If contactMap is not shared state somewhere in the call stack above the call to sendMessages() then there&#039;s no problem and no reason to incur the costs of ImmutableMap.  If it is shared then you need to weigh the costs involved.

Taking inventory of shared state is complicated by the situation where a local variable is turned into shared state like this:

    ....
    Map localMap = new TreeMap();
    ....
    someInstance.setMap(localMap);

The call to setMap() could result in localMap now being  an instance variable of someInstance.

Ideally when writing concurrent code this kind of thing would be documented in a shared state inventory, but I&#039;m dreaming.</description>
		<content:encoded><![CDATA[<p>Jim,</p>
<p>I like the idea of using immutable data structures for simple classes, but for a collection this could incur a pretty large performance hit.  Compare the performance of immutablePut() to this:</p>
<p>    synchronized(contactMap) {<br />
        sendMessages(Map contactMap);<br />
    }</p>
<p>When taking over someone else&#8217;s code I like to take inventory of where in the code shared, mutable state exists.  If contactMap is not shared state somewhere in the call stack above the call to sendMessages() then there&#8217;s no problem and no reason to incur the costs of ImmutableMap.  If it is shared then you need to weigh the costs involved.</p>
<p>Taking inventory of shared state is complicated by the situation where a local variable is turned into shared state like this:</p>
<p>    &#8230;.<br />
    Map localMap = new TreeMap();<br />
    &#8230;.<br />
    someInstance.setMap(localMap);</p>
<p>The call to setMap() could result in localMap now being  an instance variable of someInstance.</p>
<p>Ideally when writing concurrent code this kind of thing would be documented in a shared state inventory, but I&#8217;m dreaming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sue Schedin</title>
		<link>http://www.objectpartners.com/2010/02/01/immutable-data-structures-in-concurrent-java-applications/comment-page-1/#comment-416</link>
		<dc:creator>Sue Schedin</dc:creator>
		<pubDate>Tue, 02 Feb 2010 15:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectpartners.com/?p=1711#comment-416</guid>
		<description>Nice article!</description>
		<content:encoded><![CDATA[<p>Nice article!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

