<?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>Hashbrown on the Mic &#187; geek stuff</title>
	<atom:link href="http://hashbrownonthemic.com/category/geek-stuff/feed/" rel="self" type="application/rss+xml" />
	<link>http://hashbrownonthemic.com</link>
	<description>Riffs from an overheated mind</description>
	<lastBuildDate>Fri, 21 Jan 2011 14:48:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Java Concurrency For Dummies: Pt 1 &#8211; The basics</title>
		<link>http://hashbrownonthemic.com/2009/07/31/java-concurrency-for-dummies-pt-1-the-basics/</link>
		<comments>http://hashbrownonthemic.com/2009/07/31/java-concurrency-for-dummies-pt-1-the-basics/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 03:43:27 +0000</pubDate>
		<dc:creator>hashbrown</dc:creator>
				<category><![CDATA[geek stuff]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://hashbrownonthemic.com/?p=209</guid>
		<description><![CDATA[During my recent week at the JavaOne conference, I attended several sessions dealing with issues of concurrency in programming. What started as a cursory interest, turned into a strong desire to really understand these problems at a deeper level. But I&#8217;m still really a noob when it comes to this stuff, so I figure this [...]]]></description>
			<content:encoded><![CDATA[<p>During my recent week at the JavaOne conference, I attended several sessions dealing with issues of concurrency in programming.  What started as a cursory interest, turned into a strong desire to really understand these problems at a deeper level.  But I&#8217;m still really a noob when it comes to this stuff, so I figure this is a great time to try to explain it to other beginners.</p>
<p>Ok, let&#8217;s start with the basics, what is concurrency and why should you care?  Well according to <a href="http://en.wikipedia.org/wiki/Concurrency_(computer_science)">Wikipedia</a> concurrency is </p>
<blockquote><p>a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.</p></blockquote>
<p>Unless you&#8217;re writing applications that only have a few simultaneous users, chances are you will use the threading features of java to try and take advantage of the performance benefits of asynchronous processing.  Even if you are writing a simple MVC style web app, that servlet container is going to be multi-threaded and you could encounter concurrency issues in your servlet code.  The problem is, when we&#8217;re coding our app, it&#8217;s only ever exercised in a single-user scenario.  And you can&#8217;t really write unit tests to check the behavior of multi-threaded areas of your code.  Therefore, concurrency issues tend to not be identified during testing.  Usually they appear as strange, random bugs during periods of heavy load, and cannot be reliably reproduced.  Awesome.  I love those.</p>
<p>So how do we identify the areas of our application that are susceptible to concurrency issues, and how do we code for them?  Those are some pretty tough questions, I&#8217;ve found.  Maybe by the end of this series we&#8217;ll have some answers.  In the simplest of terms, managing concurrency means managing the shared state in your application, more specifically, <em>mutable shared state</em>.  That really means any instance or static class level fields that are not declared as final.  (There are some nuances to the use of the final keyword, but let&#8217;s keep it easy for now).<br />
To control concurrency issues, follow 3 rules:</p>
<ul>
<li>Don&#8217;t share state across threads.  This is done by encapsulating your state.  In the simplest example, this means that class fields are private and access is limited to one or two methods.  This will make it easier to create code that is thread-safe.</li>
<li>Make your state immutable.  If the value of your fields cannot be changed, you are already thread-safe!  Consider exposing read-only versions of your objects when possible.</li>
<li>Finally, synchronize access.  Only allow a single thread to access your state at any given time.  Most concurrency discussion centers around locking and synchronization. </li>
</ul>
<p>What does it mean to synchronize access?   Synchronization is about controlling access to state and is handled primarily through locks.  Proper synchronization guarantees 2 things:</p>
<ul>
<li>Mutual Exclusion &#8211; this guarantees that only one thread can hold a given lock, and therefore only one thread has access to the locked state(data).</li>
<li>Visibility &#8211; this guarantees that as a thread releases a lock, any changes made to shared variables, the mutable shared state, will be immediately seen by all threads, most importantly the next thread acquiring the lock.  This ensures that no threads see stale data.</li>
</ul>
<p>So, concurrent programming in a nutshell:</p>
<blockquote><p>Limit the mutable state (data that can be changed) in your objects.  When allowing others to access and change your objects state, control that state using proper synchronization.</p></blockquote>
<p>So that&#8217;s the absolute basics on concurrency, but what about Java?<br />
The fundamental power of java is its memory model and the threading facilities that are built into the language.  Along with thread support are many mechanisms to correctly handle concurrent operations.  And this will be the subject of the rest of this blog series.  Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://hashbrownonthemic.com/2009/07/31/java-concurrency-for-dummies-pt-1-the-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Interview Puzzler</title>
		<link>http://hashbrownonthemic.com/2009/06/18/java-interview-puzzler/</link>
		<comments>http://hashbrownonthemic.com/2009/06/18/java-interview-puzzler/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 23:34:30 +0000</pubDate>
		<dc:creator>hashbrown</dc:creator>
				<category><![CDATA[geek stuff]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://hashbrownonthemic.com/?p=202</guid>
		<description><![CDATA[This is a puzzler we created at my work to use as an interview problem. I had a fun time taking it myself, and got it wrong the first time! It was designed to mimic some bad legacy code you might encounter when working on a large aging system, that has passed through many hands. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a puzzler we created at my work to use as an interview problem.  I had a fun time taking it myself, and got it wrong the first time!  It was designed to mimic some bad legacy code you might encounter when working on a large aging system, that has passed through many hands.  Terrible coding practices, no javadocs or comments, etc.  You are tasked to figure out what the heck it does.<br />
First &#8211; does it compile?  If not, how do you fix it?<br />
Second &#8211; If it compiles, what is the output?</p>
<p>I&#8217;ll answer questions and post the solution in the comments.</p>
<pre class="brush: java;">
package crazy;

public class Timing extends R {
    public static final Integer t = new Integer(&quot;4&quot;);

    public static void main(String[] args) {
        Timing t = new Timing(11);

        System.out.print(t.foo);
        bat(t);
    }

    void fob() { fod(); }

    public Timing(int value) {

        super();
        foo = foo % value;
        bar();
    }

    static {
        System.out.print(&quot;6&quot;);

    }

    private void bar() {
        new Baz().bar(5);
        tr = &quot;2&quot;;
    }

    private int foo = 25;

    static void r() { System.out.println(&quot;1&quot;); }
}

abstract class R {

    String tr = &quot;9&quot;;

    static void bat(R r) {
        r.fob();
        System.out.print(r.tr);

    }

    private int negate(int bam) {
        return bam * -1;
    }

    public R() {
        System.out.print(&quot;7&quot;);
    }

    void fod() { System.out.print((int)Math.floor(.99)); }

    protected final int t() {
        return 5;
    }

    class Baz {

        void bar(int fob) {
            if (fob == 9)
                System.out.print(String.valueOf(fob++));

                System.out.print(String.valueOf(negate(fob++)));
            if (fob == 5)
                System.out.print(String.valueOf(fob+=2));

        }
    }

    static {
        System.out.print(&quot;8&quot;);
    }

    abstract void fob();

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://hashbrownonthemic.com/2009/06/18/java-interview-puzzler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Week At JavaOne</title>
		<link>http://hashbrownonthemic.com/2009/06/05/my-week-at-javaone/</link>
		<comments>http://hashbrownonthemic.com/2009/06/05/my-week-at-javaone/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 05:44:03 +0000</pubDate>
		<dc:creator>hashbrown</dc:creator>
				<category><![CDATA[geek stuff]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[javaone]]></category>

		<guid isPermaLink="false">http://hashbrownonthemic.com/?p=185</guid>
		<description><![CDATA[I just returned home from a week in San Francisco at the JavaOne conference, I mean literally like 2 hours ago. This is the first time I&#8217;ve been to any conference like this, and I had a great time! The scale of this thing is really impressive, I mean it&#8217;s huge. The planning and logistics [...]]]></description>
			<content:encoded><![CDATA[<p>I just returned home from a week in San Francisco at the <a href="http://java.sun.com/javaone/">JavaOne</a> conference, I mean literally like 2 hours ago.  This is the first time I&#8217;ve been to any conference like this, and I had a great time!  The scale of this thing is really impressive, I mean it&#8217;s huge.  The planning and logistics that go into putting on a conference of this size just amazes me.  It felt like they really went all out, all the small details were handled, and you could see the effort they put into making it a special experience.</p>
<p>I had originally registered for tech sessions Tuesday &#8211; Thursday, but Thursday night I just wasn&#8217;t ready for it to end, and ended up cramming 2 more sessions in on Friday morning before jumping in a cab for the airport.  I literally was in a cab 15 minutes after my final session.<br />
Overall, I attended 19 technical sessions over 3 1/2 days, plus the general session keynotes.</p>
<p>I attended sessions on the different dynamic scripting languages that run on the JVM, many on concurrency, and then some on how to use those dynamic languages to solve concurrency problems.  I had sessions on <a href="http://www.springsource.com/">Spring</a>, and <a href="http://jcp.org/aboutJava/communityprocess/final/jsr311/index.html">REST using JAX-RS</a>, sessions on unit testing and some of the tools available.  I had a session on defective java with the man behind <a href="http://findbugs.sourceforge.net/">FindBugs</a>, and a session on <a href="http://www.amazon.com/gp/product/0321356683?ie=UTF8&#038;tag=insightgalact-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0321356683">Effective Java (2nd Edition) </a><img src="http://www.assoc-amazon.com/e/ir?t=insightgalact-20&#038;l=as2&#038;o=1&#038;a=0321356683" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
  with one of the absolute rock-stars of the java world, Joshua Bloch.  My session on Spring 3.0 was given by THE man behind Spring, Rod Johnson.  My sessions on <a href="http://liftweb.net/">Lift</a> and <a href="http://clojure.org/">Clojure</a> were both given by the creators of the language, and the session on JAX-RS was given by the writers of the specification.  When I went to hear about how the <a href="http://code.google.com/appengine/docs/java/overview.html">Google App Engine</a> now supports java, it was directly from the 3 guys responsible for it.  I mean, talk about getting it from the source!  That google session led to a very late night with my co-worker as we sat in the bar playing with the new sdk until 1am! <span id="more-185"></span> Of course, the highlight was a late night session with the <a href="http://javaposse.com/">Java Posse</a>, the whole reason I wanted to go in the first place.  Even at the conference party on Thursday, when the band was covering Africa and Rosanna, it was the actual lead singer from Toto singing on stage!<br />
Of course, it was some of the non-session encounters that made the conference even better.  I randomly ran into the Java Posse guys in the hall and got a few words with them.  The host of the whole conference, Chris Mellisinos, happened to be sitting next to me in the hotel bar one night, and so I got to chat with him.  Sat next to the author of JAX-RS during a session on the new <a href="https://launchpad.net/drizzle">Drizzle</a> database, and then was honored to talk for a bit with Joshua Bloch when he stayed hours after his book signing just to hang with everyone.</p>
<p>If you want a bigger perspective on the conference, search twitter for the <a href="http://search.twitter.com/search?q=javaone">#javaone hashtag</a>, and follow me, <a href="http://twitter.com/hashbrown1">@hashbrown1</a>, as I was tweeting all week (when I could get a good connection).</p>
<p>So obviously I have tons of notes spread between my computer and a notepad (after my battery would die), and so I hope to be blogging in more detail about some of the things I learned.  Don&#8217;t look for it too soon though, I need to spend a few days in the yard.</p>
<p>-HB</p>
]]></content:encoded>
			<wfw:commentRss>http://hashbrownonthemic.com/2009/06/05/my-week-at-javaone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

