<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Practicing Concurrency</title>
	<atom:link href="http://concurrency.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://concurrency.wordpress.com</link>
	<description>The OCI "Java Concurrency in Practice" Study Group</description>
	<lastBuildDate>Tue, 24 Apr 2007 23:48:01 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='concurrency.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/b51b8f03b4a990f783118c0572c86963?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Practicing Concurrency</title>
		<link>http://concurrency.wordpress.com</link>
	</image>
			<item>
		<title>Swing versus SWT Thread Confinement</title>
		<link>http://concurrency.wordpress.com/2007/04/24/swing-versus-swt-thread-confinement/</link>
		<comments>http://concurrency.wordpress.com/2007/04/24/swing-versus-swt-thread-confinement/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 23:48:01 +0000</pubDate>
		<dc:creator>Eric Burke</dc:creator>
				<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://concurrency.wordpress.com/2007/04/24/swing-versus-swt-thread-confinement/</guid>
		<description><![CDATA[Swing, SWT, and most (maybe all?) GUI APIs operate under some sort of thread confinement scheme. Most readers of this blog are probably somewhat familiar with the AWT/Swing event dispatch thread. Swing components are not thread-safe &#8212; they are thread-confined. This means when you call methods on Swing components, you must ensure you do so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=7&subd=concurrency&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Swing, SWT, and most (maybe all?) GUI APIs operate under some sort of thread confinement scheme. Most readers of this blog are probably somewhat familiar with the AWT/Swing event dispatch thread. Swing components are not thread-safe &#8212; they are thread-confined. This means when you call methods on Swing components, you must ensure you do so on the event dispatch thread. There are a handful of thread-safe exceptions to the rule, such as repaint().</p>
<p>During our last meeting it was brought to my attention that SWT adheres to a fail-fast policy. If you invoke SWT API methods from a foreign thread, an SWTException is thrown. Yes! This is the way to do it.</p>
<p>Swing, on the other hand, does not fail fast. Instead, if you execute Swing API methods outside the EDT, your app might work&#8230;or it might exhibit strange behaviour. You might notice painting artifacts, obscure exceptions, and possibly may encounter memory visibility issues on multi-processor systems.</p>
<h2>Can We Fix Swing?</h2>
<p>I suspect that most developers will agree a fail-fast approach works best. If your code has a bug, you may as well fail immediately with a specific exception (as SWT does), rather than live with subtle bugs (as Swing does) that are much harder to diagnose.</p>
<p>One approach involves changing every method in Swing as follows:</p>
<p>public void doSomething() {<br />
  if (!SwingUtilities.isEventDispatchThread()) {<br />
    throw new IllegalStateException(&#8220;&#8230;blah blah blah&#8230;&#8221;);<br />
  }<br />
  &#8230;normal code<br />
}</p>
<p>Of course those three lines of code could be encapsulated into a helper-function of some sort, but the concept remains the same. This would require sweeping changes to Swing and is unlikely to happen. Throwing an exception, while arguably correct, does change the contract of these methods. Even if we do not like the current behavior, changing the semantics of nearly every Swing method may break quite a bit of code.</p>
<h2>A More Serious Proposal</h2>
<p>I believe annotations offer a more viable solution. Imagine if Java 7 Swing code added annotations to every Swing method that requires the EDT:</p>
<p>@RequiresEDT<br />
public void doSomething() {<br />
    &#8230;normal code<br />
}</p>
<p>A new @RequiresEDT annotation would not change the behavior of any existing Swing API. It would, however, clearly document the intent of every Swing method. Furthermore, having that annotation in place (with runtime retention) makes it drop dead simple to use an AOP framework to enforce proper thread confinement. Or IDEs can more easily offer inspections that warn you of threading bugs.</p>
<p>Thoughts? Is this something we should pursue adding to Java 7?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/concurrency.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/concurrency.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/concurrency.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/concurrency.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/concurrency.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/concurrency.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/concurrency.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/concurrency.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/concurrency.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/concurrency.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/concurrency.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/concurrency.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=7&subd=concurrency&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://concurrency.wordpress.com/2007/04/24/swing-versus-swt-thread-confinement/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760389c958cc9ab10b0e6a65088d3144?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Eric</media:title>
		</media:content>
	</item>
		<item>
		<title>Volatile Variable Inspections</title>
		<link>http://concurrency.wordpress.com/2007/04/24/volatile-variable-inspections/</link>
		<comments>http://concurrency.wordpress.com/2007/04/24/volatile-variable-inspections/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 14:34:47 +0000</pubDate>
		<dc:creator>Brian Coyner</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Volatile]]></category>

		<guid isPermaLink="false">http://concurrency.wordpress.com/2007/04/24/volatile-variable-inspections/</guid>
		<description><![CDATA[Modern IDEs (IDEA, Eclipse) provide developers with lots of assistance when writing code. These IDEs mark code that is:

just plain wrong (won&#8217;t compile)
not used
can be simplified
and lots more

Can modern IDEs help developers find threading bugs? Let&#8217;s take a look at a specific example and find out.
public class Example {

    private boolean running [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=4&subd=concurrency&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Modern IDEs (IDEA, Eclipse) provide developers with lots of assistance when writing code. These IDEs mark code that is:</p>
<ul>
<li>just plain wrong (won&#8217;t compile)</li>
<li>not used</li>
<li>can be simplified</li>
<li>and lots more</li>
</ul>
<p>Can modern IDEs help developers find threading bugs? Let&#8217;s take a look at a specific example and find out.</p>
<pre>public class Example {

    private boolean running = true;

    /**
     * Thread A starts counting
     */
    public void startCounting() {

        // Thread A keeps going until Thread B calls stop. Thread A may never stop!
        while (running) {
            countSomeSheep();
        }
    }

    /**
     * Thread B calls stop.
     */
    public void stop() {
        this.running = false;
    }

    /**
     * Executed by thread A.
     */
    private void countSomeSheep() {
        // zzz zzz zzz
    }
}</pre>
<p>So what is wrong with the code? For a great explanation please review 3.1.4 Volatile variables in &#8220;Java Concurrency In Practice&#8221; book. </p>
<p>After reading that section you understand why the boolean variable named <code>running</code> should be marked <code>volatile</code>.</p>
<p>Let&#8217;s turn our attention to my favorite IDE for help tracking down this threading problem. <a href="http://www.jetbrains.net/confluence/display/IDEADEV/Selena+EAP">IDEA</a> (version 7, code named Selena) has an inspection named &#8220;While loop spins on field&#8221;. Here is the inspection&#8217;s description:</p>
<blockquote><p>This inspection reports on any instances of while loops which spin on the value of a non-volatile field, waiting for it to be changed by another thread. In addition to being potentially extremely CPU intensive when little work is done inside the loop, such loops are likely have different semantics than intended, as the Java Memory Model allows such field accesses to be hoisted out of the loop, causing the loop to never complete even if another thread does change the field&#8217;s value.</p></blockquote>
<p>Here is a snapshot of IDEA highlighting the threading problem:<br />
<img src="http://concurrency.files.wordpress.com/2007/04/not_volatile.png" alt="Non-Volatile IDEA Inspection" /></p>
<p>Here is a snapshot of IDEA after making <code>running</code> volatile:<br />
<img src="http://concurrency.files.wordpress.com/2007/04/volatile.png" alt="" /></p>
<p><strong>NOTE:</strong> IDEA 6.0.5 also has this inspection but it did not work!<br />
<strong>NOTE:</strong> I have no idea if Eclipse has a similiar inspection.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/concurrency.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/concurrency.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/concurrency.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/concurrency.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/concurrency.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/concurrency.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/concurrency.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/concurrency.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/concurrency.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/concurrency.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/concurrency.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/concurrency.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=4&subd=concurrency&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://concurrency.wordpress.com/2007/04/24/volatile-variable-inspections/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a6c16fd5459ba7b845f1c566a2151855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">beanman</media:title>
		</media:content>

		<media:content url="http://concurrency.files.wordpress.com/2007/04/not_volatile.png" medium="image">
			<media:title type="html">Non-Volatile IDEA Inspection</media:title>
		</media:content>

		<media:content url="http://concurrency.files.wordpress.com/2007/04/volatile.png" medium="image" />
	</item>
		<item>
		<title>So far</title>
		<link>http://concurrency.wordpress.com/2007/04/23/so-far/</link>
		<comments>http://concurrency.wordpress.com/2007/04/23/so-far/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 04:24:27 +0000</pubDate>
		<dc:creator>dennisradio</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://concurrency.wordpress.com/2007/04/23/so-far/</guid>
		<description><![CDATA[Nate touched on some of the features the newer versions of Java provide for concurrency at an OCI Java Lunch a couple of months earlier.  Eric&#8217;s follow on Java Lunch concurrency topic nurtured the planted seed, but the BIG THANKS goes to Charles (I like calling him Charlie, with NO idea what he thinks) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=3&subd=concurrency&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Nate touched on some of the features the newer versions of Java provide for concurrency at an <a href="http://www.ociweb.com/" title="Object Computing Inc." target="_blank">OCI</a> Java Lunch a couple of months earlier.  Eric&#8217;s follow on Java Lunch concurrency topic nurtured the planted seed, but the BIG THANKS goes to Charles (I like calling him Charlie, with NO idea what he thinks) for sending out an email that provided the tipping point.  I&#8217;m repeating facts (one of my patterns)&#8230; on to the show&#8230;</p>
<p>The screen shimmers and waves to a clear picture of six people sitting around a conference table.  Some with books, others with laptops.  Charles provides introductions and greetings, one attendee is even on the other side of a speaker phone working from home.  The lunch time study group is REALLY on it&#8217;s way.</p>
<p>Chapter two of <a href="http://safari.oreilly.com/0321349601" title="Java Concurrency in Practice" target="_blank">JCIP</a> &#8220;Thread Safety&#8221; propones that the issue is about &#8220;managing access to <em>state</em>&#8230; shared mutable state&#8221;.  If our programs don&#8217;t manage this correctly they are broke.  That&#8217;s a capital period.  The idea that&#8217;s trying to be communicated is that, what we used to believe about visibility of variables and objects, the order of execution  of code, even the values that a variable has no longer is as simple as it was. Specifically when <strike>programs</strike> threads start running concurrently.</p>
<p>For me the moment of &#8216;Oh no, now what am I going to do&#8217; came when it was pointed out the increment operation (i++) is not atomic, that it is a read, modify and write.  The chapter went on to provide several insights into ways I need to think differently if I&#8217;m writing code for multiple thread access.  Covering the topics of Atomicity, Locks, Guards, Liveness and Performance I was able to quickly grasp the authors&#8217; definitions.</p>
<p>The book clearly shows me code that is broke and steers me to solutions on what I can do to make it correct.  I am MOST grateful for the bits of humor, there is just not enough levity in this world.  I enjoyed the discussion around the table and the time went by quickly.  I was in a bit of a hurry, my tee time was quickly approaching.  Slow fade&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/concurrency.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/concurrency.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/concurrency.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/concurrency.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/concurrency.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/concurrency.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/concurrency.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/concurrency.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/concurrency.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/concurrency.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/concurrency.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/concurrency.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=3&subd=concurrency&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://concurrency.wordpress.com/2007/04/23/so-far/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/49c70930733139242a4af2b44eb77446?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dennisradio</media:title>
		</media:content>
	</item>
		<item>
		<title>What is This?</title>
		<link>http://concurrency.wordpress.com/2007/04/23/hello-world/</link>
		<comments>http://concurrency.wordpress.com/2007/04/23/hello-world/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 18:35:49 +0000</pubDate>
		<dc:creator>Eric Burke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Back on March 29, 2007, Charles Sharp sent this email to his fellow OCI/Advantage employees:
Greetings All,
Now that Eric has whetted your appetite for Java&#8217;s take on concurrency (or thrown you into a panic due to your understanding level), I thought this would be a good time to see if there is an interest in getting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=1&subd=concurrency&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Back on March 29, 2007, Charles Sharp sent this email to his fellow OCI/Advantage employees:</p>
<blockquote><p>Greetings All,</p>
<p>Now that Eric has whetted your appetite for Java&#8217;s take on concurrency (or thrown you into a panic due to your understanding level), I thought this would be a good time to see if there is an interest in getting a  study group together to go through the book, <strong><em>Java Concurrency in Practice</em></strong> by Brian Goetz et al.</p>
<p>The study will be done in two parts.  The book has 16 chapters.  Part one of the study would cover chapters 2 through 9.  Part two would cover 10 through 16.  We&#8217;ll decide about Part two after we see how Part one goes.</p>
<p>Today I&#8217;m soliciting people to participate in Part one.</p>
<p>There will be eight meetings.  (The group might decide to have a pre-study organizational meeting to discuss and argue about format changes in the usual uninteresting fashion.)</p>
<p>Study meetings will be held during lunch hour (something like 11:30 to 12:30 with a half-hour overrun buffer to 1:00) once a week at the OCI office.</p>
<p>Due to other meetings through the week, I&#8217;m proposing either Monday, Wednesday, or Thursday as the meeting day.</p>
<p>The format of a meeting, as is always the case with a group of experienced wonks, is open for discussion.  Here&#8217;s a first pass to start that discussion.</p>
<p>Everyone reads the week&#8217;s chapter before the meeting.  (From my perspective, this is non-negotiable.  If you don&#8217;t have time to read a chapter a week, you just don&#8217;t have time to sign up for the study group.)</p>
<p>Each week one person will be assigned the chore of providing code that illustrates the concepts discussed in the week&#8217;s chapter.  I expect most of the attendees relate to code examples as well as anything.  So please note that part of what you&#8217;re signing up for is to provide this illustrative code for one of the meetings.</p>
<p>After the code presentation and attending discussion, I would like to leave time to do a quick &#8220;round the table&#8221; where each attendee has a chance to pitch in some point (or points) from the book that didn&#8217;t get covered.</p>
<p>And that&#8217;s pretty much the format plan.  In summary, we&#8217;re agreeing to meet once a week for eight weeks and do the homework.</p>
<p>If that sounds like your idea of fun, please stay away from me.</p>
<p>If that sounds like something that would be useful and constructive and a good leg up in understanding some crucial concepts, then give me a shout via reply email.</p></blockquote>
<p>And thus, the study group was formed. We first met last week on Monday, April 16, and have met every Monday since then! Enjoy.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/concurrency.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/concurrency.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/concurrency.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/concurrency.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/concurrency.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/concurrency.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/concurrency.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/concurrency.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/concurrency.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/concurrency.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/concurrency.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/concurrency.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=concurrency.wordpress.com&blog=1018762&post=1&subd=concurrency&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://concurrency.wordpress.com/2007/04/23/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760389c958cc9ab10b0e6a65088d3144?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Eric</media:title>
		</media:content>
	</item>
	</channel>
</rss>