<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Transient Technology &#187; concurrency</title>
	<atom:link href="http://martinaharris.com/tag/concurrency/feed/" rel="self" type="application/rss+xml" />
	<link>http://martinaharris.com</link>
	<description>Next time you look it might be gone</description>
	<lastBuildDate>Wed, 25 Apr 2012 09:52:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>5 exciting things coming with Spring 3.0</title>
		<link>http://martinaharris.com/2009/11/5-things-spring-3-0/</link>
		<comments>http://martinaharris.com/2009/11/5-things-spring-3-0/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 05:00:00 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=129</guid>
		<description><![CDATA[In a previous blog entry I wrote about the now ancient announcement that spring 2.5 would be available. On the 2nd anniversary of that announcement I would like to examine the things I am looking forward to in Spring 3.0. &#8230; <a href="http://martinaharris.com/2009/11/5-things-spring-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://martinaharris.com/2009/11/5-reasons-to-upgrade-spring-to-2-5/" TARGET="_blank">previous blog entry</a> I wrote about the now ancient announcement that spring 2.5 would be available.  On the 2nd anniversary of that announcement I would like to examine the things I am looking forward to in Spring 3.0.</p>
<p><a href="http://www.springsource.org/node/2174" TARGET="_blank"><strong>Release Announcement:</strong> 13/11/2009</a></p>
<h3>5 cool things available in Spring 3.0</h3>
<ol>
<li>Java 5 fully used throughout the whole API.  In 2.5 the core is still Java 1.4 compatible, 3.0 is written in and requires Java 5.0.  This means much greater use of generics.  Unrelated but they have also included many performance enhancements.</li>
<li>SpEL.  Spring Expression Language gives access to nested bean definitions and system properties via #{…} syntax in property values.  These dynamic #{…} expressions and static ${…} placeholders can also be used to inject property settings via the @Value annotation.  This should much simplify property setting.</li>
<li>Comprehensive REST support.  Spring 2.5 MVC is an excellent pattern.  The simplicity of annotated controllers results in very clean implementations.  3.0 takes this system further by building in Restful support and a RestTemplate for clientside REST.</li>
<li>Spring 3.0 UI Field Formatting.  Springs formatting system has always been useful in web and desktop applications.  Its an effective way to remove a lot of boilerplate code from a system.  This new system of annotations allows common formats to be applied to classes, model properties and methods.  <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch05s06.html#ui-format-Formatted-Annotation" TARGET="_blank">Check it out its very cool.</a></li>
<li>Many enhancements migrating to java.util.concurrent including ThreadPoolExecutorFactoryBean which exposes the native ExecutorService interface.  The concurrent package is very good indeed, so bringing more support into spring is just fantastic.</li>
</ol>
<p>Of the 5 mentioned here its only the tip of the iceberg as regards new features.  This release is very rich.  As usual with spring its when you have something to solve that you really appreciate it.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F&amp;title=5+exciting+things+coming+with+Spring+3.0" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F&amp;title=5+exciting+things+coming+with+Spring+3.0" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F&amp;title=5+exciting+things+coming+with+Spring+3.0" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F&amp;headline=5+exciting+things+coming+with+Spring+3.0" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=5+exciting+things+coming+with+Spring+3.0&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=5+exciting+things+coming+with+Spring+3.0&amp;u=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=5+exciting+things+coming+with+Spring+3.0&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=5+exciting+things+coming+with+Spring+3.0&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=5+exciting+things+coming+with+Spring+3.0&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F&amp;title=5+exciting+things+coming+with+Spring+3.0&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F11%2F5-things-spring-3-0%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2009/11/5-things-spring-3-0/';
var dzone_title = '5 exciting things coming with Spring 3.0';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2009/11/5-things-spring-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactoring to Google Collections &#8211; ImmutableList  for simple code</title>
		<link>http://martinaharris.com/2009/10/google-collection-refactor-simplifies-implementation/</link>
		<comments>http://martinaharris.com/2009/10/google-collection-refactor-simplifies-implementation/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 14:37:13 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[immutable]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=54</guid>
		<description><![CDATA[Google collections are excellent in multi-threaded applications, so I thought I would re-factor some code to use them. <a href="http://martinaharris.com/2009/10/google-collection-refactor-simplifies-implementation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was reading this excellent post on <a href="http://blog.jayway.com/2009/10/22/google-collections/" target="_blank">google collections by Sune Simonsen</a> and decided to re-factor some code of mine.  I have an immutable results object used in a multi-threaded application.  I wanted to feel the difference using the google ImmutableList.  My existing class provides immutability in a very similar way to the google classes.  Static methods are used to instantiate the object.  An array is used to back a list collection.  Defensive copies are made to protect the immutability of the object.  Moving to <a href="http://code.google.com/p/google-collections/" target="_blank">google collections</a> is easy and makes my implementation simple whilst reducing test overhead.</p>
<p><span id="more-54"></span></p>
<h3>Steps taken to refactor</h3>
<p>There was actually very little to do.</p>
<p><strong>Step 1, add a maven dependency</strong></p>
<pre class="brush: xml; gutter: false">
<dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0-rc3</version>
            <type>jar</type>
</dependency>
</pre>
<p><strong>Step 2, replace the array with an ImmutableList</strong></p>
<pre class="brush: java; light: true">
private static final LineResult[] EMPTY_LINERESULT_ARRAY = new LineResult[0];
private LineResult[] lineResults = EMPTY_LINERESULT_ARRAY;
</pre>
<p>could become:</p>
<pre class="brush: java; light: true">
private List&lt;LineResult&gt;  lineResults = ImmutableList.of();
</pre>
<p>In the end I used ImmutableList to clearly my intent.  The usage is internal to the class so there is no advantage in using the List interface.</p>
<pre class="brush: java; light: true">
private ImmutableListst&lt;LineResult&gt;  lineResults = ImmutableList.of();
</pre>
<p><strong>Step 3, The constructor and static factory methods are simplified</strong><br />
We are no longer using an array to back the list, so the protective copy can be moved from the constructor into the static method.  This reduces the window of vulnerability you are exposed to before capturing the data held in the list.  This is a direct result of the google class providing a static factory method.  Nb.  Its a shame that the standard collections don&#8217;t provide static factory methods.</p>
<p>Prior to the changes the protective copy was done in construction like this.</p>
<pre class="brush: java; light: true">
 this.lineResults = lineResults.toArray(EMPTY_LINERESULT_ARRAY);
</pre>
<p>This result is a much simpler constructor.</p>
<pre class="brush: java; light: true; highlight: 3">
private ResultsFileSearch(File fileFound, ImmutableList&lt;LineResult&gt; lineResults) {
        this(fileFound);
        this.lineResults = lineResults;
}
</pre>
<p>My newInstance method makes use of the ImmutableList.copyOf static factory method resulting in a very clean conversion of List into Immutable list.  Note that generics is inferring the type.</p>
<pre class="brush: java; light: true; highlight: 4">
public static ResultsFileSearch newInstance(File fileFound
                 , List&lt;LineResult&gt; lineResults) {
        return new ResultsFileSearch(fileFound
                        ,ImmutableList.copyOf(lineResults));
}
</pre>
<p><strong>Step 4, the getLineResults method no longer has to deal with the array or conversion.</strong><br />
The original array backed object had to deal with returning either an empty list or conversion to an unmodifiable list.  There are two things I did not like about this when I wrote the original.</p>
<ul>
<li>The code has to check the array resulting in some conditional logic.  This increases the test overhead slightly.</li>
<li>The use of Collections.unmodifiableList(Arrays.asList(lineResults)); is very ugly and slow.</li>
</ul>
<p>This was the original, <em>note the subtle bug when returning an empty list</em>.</p>
<pre class="brush: java; light: true">
 public List&lt;LineResult&gt; getLineResults() {

        if ((this.lineResults.length == 0)) {
            return Collections.emptyList();
        } else {
            return Collections.unmodifiableList(Arrays.asList(lineResults));
        }
        return this.lineResults;
}
</pre>
<p>I hope you agree its a much simpler version using the google code.  As we are now using the Immutable implementation, we don&#8217;t have to worry about exposing the reference.</p>
<pre class="brush: java; light: true">
public List&lt;LineResult&gt; getLineResults() {
        return this.lineResults;
}
</pre>
<h3>Conclusions</h3>
<p>Using the google collections makes my implementation much cleaner.  Several complexities are given over to the google collections classes.  Moreover testing of my class is simpler.  The changes are contained within the class.  None of the method signatures change, which has two consequences.  On the plus side the re-factor is contained within this class.  On the negative side, any code modifying the list will raise an UnsupportedOperationException which was no different to my original version.  The construction of my class might be slightly slower, the memory overhead slightly bigger now that we are not using the array.  Counter to this, the getLineResults method is quicker as it now only returns a reference.  In my program this is more important as architecturally it uses bounded queues to hold these objects for processing by threads.  So although its using a little extra memory, its constrained.  The performance gain is worth it.</p>
<p>I recommend using the com.google.common.collect package but adhere to the <a href="http://code.google.com/p/google-collections/wiki/Faq" target="_blank">caveats</a> i.e don&#8217;t expose the types in an API etc.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F&amp;title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F&amp;title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F&amp;title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F&amp;headline=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;u=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F&amp;title=Refactoring+to+Google+Collections+-+ImmutableList++for+simple+code&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F10%2Fgoogle-collection-refactor-simplifies-implementation%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2009/10/google-collection-refactor-simplifies-implementation/';
var dzone_title = 'Refactoring to Google Collections &#8211; ImmutableList  for simple code';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2009/10/google-collection-refactor-simplifies-implementation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

