<?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"
	>

<channel>
	<title>A frog's eye view of the world &#187; java</title>
	<atom:link href="http://tim.littlebluefrog.com/wp-rss2.php?cat=7" rel="self" type="application/rss+xml" />
	<link>http://tim.littlebluefrog.com</link>
	<description>Take one blue frog, add caffeine and stir till the early hours of the morning. Serve with wine.</description>
	<pubDate>Mon, 07 Feb 2011 02:03:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Fixing Random Crashes in JNI Code</title>
		<link>http://tim.littlebluefrog.com/archives/797</link>
		<comments>http://tim.littlebluefrog.com/archives/797#comments</comments>
		<pubDate>Tue, 02 Jun 2009 08:38:35 +0000</pubDate>
		<dc:creator>tim</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[nerdling]]></category>

		<category><![CDATA[jni]]></category>

		<category><![CDATA[pain]]></category>

		<category><![CDATA[portico]]></category>

		<category><![CDATA[signal handling]]></category>

		<guid isPermaLink="false">http://tim.littlebluefrog.com/?p=797</guid>
		<description><![CDATA[Do you have an application that uses JNI to provide a C/C++ interface to a Java library? Are you experiencing random crashes and segmentation faults in seemingly unrelated parts of said application? Have you pulled out all your hair while trying to figure out what the problem is?
The good news is that I may have [...]]]></description>
			<content:encoded><![CDATA[<p>Do you have an application that uses JNI to provide a C/C++ interface to a Java library? Are you experiencing random crashes and segmentation faults in seemingly unrelated parts of said application? Have you pulled out all your hair while trying to figure out what the problem is?</p>
<p>The good news is that I may have a solution for you!</p>
<p>I was recently testing <a href="http://www.porticoproject.org">Portico</a> with a large, widely deployed C++ application. The Portico C++ interface uses JNI to wrap the core Java library. Other applications then link against this interface and use the library to do whatever it is they need to do.</p>
<p>When testing this large application I noticed a lot of crashes in code that was totally unrelated to Portico. For the life of me I couldn&#8217;t figure out what the problem was. This was made even more frustrating by the lack of any help from Google. Eventually however, I stumbled across <a href="http://javajiggle.com/2008/01/06/if-jni-based-application-is-crashing-check-signal-handling/">this</a> post, which discusses something that sounded quite familiar.</p>
<p>My current understanding is that the JNI uses various signals to complete its work, and that if you have an application that puts its own signal handlers in place, they will replace the JNI handlers thus causing problems. You can try starting the JVM with <code>-Xrs</code> to make it reduce signal use, but this doesn&#8217;t entirely eliminate it, potentially leaving you with the problem. </p>
<p>Fortunately, Sun ship a signal handler chaining library with the JVM. When I linked against that (no code change required!) everything started to work happily! The <code>libjsig.so</code> library is in the same directory as <code>libjvm.so</code> which you need to link against anyway, so the grand solution is to just as a <code>-ljsig</code> to your compile/linking command. Talk about a simple solution to an incredibly frustrating problem. For full details see the article above.</p>
<p>I&#8217;ve decided to post this little discovery here in the hope that Google finds it and saves someone else a whole bunch of pain. Never say I don&#8217;t do anything for you Internet.</p>
<p>Useful resources:<br />
<a href="http://javajiggle.com/2008/01/06/if-jni-based-application-is-crashing-check-signal-handling/">If JNI based application is crashing, check signal handling!</a><br />
<a href="http://www.ibm.com/developerworks/java/library/i-signalhandling/">Revelations on Java signal handling and termination</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tim.littlebluefrog.com/archives/797/feed</wfw:commentRss>
		</item>
		<item>
		<title>Feeling like a Git</title>
		<link>http://tim.littlebluefrog.com/archives/735</link>
		<comments>http://tim.littlebluefrog.com/archives/735#comments</comments>
		<pubDate>Sun, 25 Jan 2009 06:47:16 +0000</pubDate>
		<dc:creator>tim</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[nerdling]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://tim.littlebluefrog.com/?p=735</guid>
		<description><![CDATA[I keep hearing about how cool Git is, and how much better it is than Subversion, so much more powerful and flexible. I must admit that every time I look at Git I tend to notice something new interesting that I feel I could use in my day-to-day development life. Sadly, every time I try [...]]]></description>
			<content:encoded><![CDATA[<p>I keep hearing about how cool <a href="http://git-scm.com">Git</a> is, and how much better it is than Subversion, so much more powerful and flexible. I must admit that every time I look at Git I tend to notice something new interesting that I feel I could use in my day-to-day development life. Sadly, every time I try to go a little bit further I&#8217;m left with this feeling that Git is very&#8230; &#8220;Linux&#8221; (for want of a better description).</p>
<p>It feels like there are 400 commands, each of which is basically the same, yet possessing subtle differences; only 4 of which I&#8217;m ever going to use. It seems, as an inexperienced Git user, like I&#8217;m drowning in a pool of commands that all look the same and give me no indication as to which are more important or more common than the others.</p>
<p>To put it another way, I keep hearing about the &#8220;power&#8221; but it seems like nobody is paying attention to the &#8220;usability&#8221;.</p>
<p>I&#8217;m sure I&#8217;ll get rubbished for that by people who want to tell me it&#8217;s much more usable than Subversion because you can do x, y and z (or you can do them easier than you can in Subversion). While that might be true, I don&#8217;t define usability as a list of things you can do, but rather how easy it is to figure out what I need to do without having to dive into mountains of man pages or countless tutorials.</p>
<p>For example, consider the typical command used to commit something with Git:</p>
<pre>git commit -a</pre>
<p>-a? what&#8217;s the -a?</p>
<p>A quick look at the man page tells me:</p>
<p><i>Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.</i></p>
<p>Great. Everybody get that? No? I didn&#8217;t think so. What the hell is the stage and what has it got to do with my commit? I just want to commit my stuff dammit!</p>
<p>If you trawl any number of the Git tutorials Google finds, they&#8217;ll either ignore the -a like it&#8217;s not even there, or offer some cursory explanation that amounts to &#8220;everyone does it that way&#8221;. I&#8217;m left to wonder, if everyone does it that way, why isn&#8217;t that the default?! Sure, I could ignore it, but like a lot of developers I&#8217;m an anal-retentive. Leaving it there, not knowing why, just gnaws at me, like that little switch is laughing at me knowing I can&#8217;t get rid of him despite not wanting him there. Or maybe I can get rid of him&#8230;? who the hell knows. I just want to commit my stuff and move on with life.</p>
<p>Let me give you another example. Consider the situation where I want to revert back to the way the repository was before I started making my most recent changes. Perhaps I deleted a file and now I want it back.</p>
<p>Git documentation and tutorials start throwing all these things at me. There&#8217;s <code>git-revert, </code><code>git-reset</code>, <code>git-reset --soft</code> and <code>git-reset --hard</code>. Even worse, there are all these warnings about being careful when using some of them.</p>
<p>I type &#8220;git revert&#8221; and it wants more command line arguments. Further, the options it throws at me talk about editing commit messages or not doing a commit. Of course I don&#8217;t want to do a commit, I want to get back to a known-good state! I give up on revert and try &#8220;git reset&#8221;, it tells me that the file I accidently deleted was locally modified, giving me a hint of hope that Git has seen this and reverted my state. A quick check reveals&#8230; NOTHING! git-status confirms that the file is still deleted. What happened? I don&#8217;t know. I try &#8220;git reset &#8211;soft&#8221; and get no output. I check the status again and again I see that nothing has happened. I finally give up and try for what feels like the a-bomb option, &#8220;git reset &#8211;hard&#8221;. Huzzah! It worked! Why? No ******* idea, but it worked. What is the point of revert, reset or reset &#8211;soft? I still have no idea. I&#8217;m sure there is a point, but I just wanted to get a file back.</p>
<p>Just telling me that I have to use -a or &#8211;hard isn&#8217;t a solution. If I HAVE to use a particular switch to complete some common, simple task, I should be able to understand why without having to learn a whole bunch about the way Git works internally.</p>
<p>I think this is what Subversion really gets right. There are a small bunch of core commands that are well defined, well named and &#8220;do what they say&#8221;. Yes, for some tasks SVN is cumbersome or might not even do what you want, but it gets the fundamental usability ideas right.</p>
<p>Don&#8217;t get me wrong, as with Linux, once you climb the learning curve everything might be fine. Before I used a Mac I ran Gentoo. Although I hated it at first, I grew to love it (faults and all) over time, but the learning curve required <a href="http://en.wikipedia.org/wiki/Crampons">Crampons</a>, and in reality, the hostility of it is going to turn a lot of people off.</p>
<p>This whole class of problem, this lack of intuitiveness, is why I describe the experience as very &#8220;Linux&#8221;. It&#8217;s all there, it&#8217;s all functional, it can do amazing things when utilized properly, but the whole thing can is so terribly unintuitive that I just end up annoyed and going back to a tool that 95% of the time, gets out of my way.</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.littlebluefrog.com/archives/735/feed</wfw:commentRss>
		</item>
		<item>
		<title>The Beckoning Silence</title>
		<link>http://tim.littlebluefrog.com/archives/731</link>
		<comments>http://tim.littlebluefrog.com/archives/731#comments</comments>
		<pubDate>Wed, 21 Jan 2009 01:07:51 +0000</pubDate>
		<dc:creator>tim</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[nerdling]]></category>

		<category><![CDATA[offices]]></category>

		<category><![CDATA[open-plan]]></category>

		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://tim.littlebluefrog.com/?p=731</guid>
		<description><![CDATA[I had an interesting experience yesterday, one that tied together a couple of things I&#8217;ve picked up in the various streams of news that have flowed across my browser and RSS reader of late.
Late last year, Joel talked about the new Fog Creek offices they&#8217;d just completed and were moving into. Apart from looking absolutely [...]]]></description>
			<content:encoded><![CDATA[<p>I had an interesting experience yesterday, one that tied together a couple of things I&#8217;ve picked up in the various streams of news that have flowed across my browser and RSS reader of late.</p>
<p>Late last year, <a href="http://www.joelonsoftware.com/">Joel</a> talked about the <a href="http://www.joelonsoftware.com/items/2008/12/29.html">new Fog Creek offices</a> they&#8217;d just completed and were moving into. Apart from looking absolutely amazing, one of the main things that stands out is individual offices for programmers. This is one of Joel&#8217;s central requirements for office design and he has spoken about it many times before. Apart from generally wanting to create a programmer nirvana, he firmly believes that private offices enhance productivity and ultimately allow his employees to be happier and more effective.</p>
<p>On reflection, I did mostly agree with Joel. Having previously worked from a home office, the quiet environment allowed me to be incredibly productive. My main problem when working from home was that I missed the human interaction that you get working in an office environment. Every now and then I&#8217;d fly out to Perth to visit the main office. I always enjoyed these times. The office was much more active and vibrant. It had a strange appeal I couldn&#8217;t quite describe.</p>
<p align="center"><a href="http://picasaweb.google.com/spolsky/FogCreekSNewOffice#"><img src="http://www.joelonsoftware.com/items/2008/12/29-office.jpg" width="450"/></a></p>
<p>Last week I noticed the article <a href="http://www.news.com.au/business/story/0,27753,24906913-5017672,00.html">Open-plan offices are making workers sick</a>. Among the many things it pointed out was a statement that the continual activity of open plan offices is distracting and contributes to lowering productivity of employees.</p>
<p>The argument seemed to make sense, but I didn&#8217;t quite realise just how much sense it made until yesterday. At the moment I&#8217;m working on implementing a new service in <a href="http://porticoproject.org">Portico</a>. Having been through this before with the other services in the HLA specification, I know that the early parts of development require a bit of extra thinking as you try and figure out how everything hangs together. Sitting down and designing it all out, as well as implementing the initial stuff is half the battle. After that, the rest of the work is really just repeating the early stages with slight variations and testing it all.</p>
<p>I&#8217;m someone who finds noise quite distracting when I&#8217;m trying to think. For a lot of tasks I&#8217;m OK, but when I&#8217;m really trying to think, when I&#8217;m really concentrating, I can&#8217;t stand noise. Naturally this doesn&#8217;t gel well with the open-plan environment. Yesterday, to escape it all, I picked up my laptop and carted it down to the board room.</p>
<p>The effect was amazing. Two hours whisked by like it was 15 minutes. I was able to sit there and concentrate, not having my flow interrupted by the conversations or the comings and goings of others. Not only was I productive during that time, but I felt fresher at a time of the day when I&#8217;m normally starting to wind down. I was ready to keep on working.</p>
<p>I also noticed that I spent less time mindlessly wandering the internet. Not once in the entire session did I check my email, wander onto the Portico support forums or flick over to <a href="http://digg.com">Digg</a>. Sitting in a distraction free environment caused me to spend less time distracting myself. This I found particularly interesting, as if the availability of time-wasters like Digg, Flickr, Twitter and the Internet in general were only crutches I used to reset my system when I lost my flow after an interruption. Taking away the interruption prone environment meant I remained focused on what I was doing longer and less aware of (or in need of) digital diversions of my own.</p>
<p>Programming in the <a href="http://www.devx.com/DevX/Article/11659">flow</a> is essential to both <i>being</i> productive and <i>feeling</i> productive. Sitting out here in an open-plan office, I can feel my flow being constantly interrupted. In such an environment this kind of distraction is unavoidable. Sometimes it&#8217;s nice, sometimes you crave the distraction and it inadvertently gives you the mental break you need. More often then not, it is disruptive. I can feel it slowing me down, and worse still, I can feel it wearing me down, tiring me out.</p>
<p>Open-plan offices do have many advantages. They&#8217;re cheaper to fit out, people can bounce off one another, I tend to find them lighter and brighter (they would be much better than a windowless office at the end of a windowless hallway!). Open-plan offices are everywhere and I&#8217;m just going to have to find a way to deal with it, but I do miss the productivity I used to have, even if I do now get the social interaction I previously desired.</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.littlebluefrog.com/archives/731/feed</wfw:commentRss>
		</item>
		<item>
		<title>JGroups and Daemon Threads</title>
		<link>http://tim.littlebluefrog.com/archives/632</link>
		<comments>http://tim.littlebluefrog.com/archives/632#comments</comments>
		<pubDate>Mon, 25 Aug 2008 08:25:44 +0000</pubDate>
		<dc:creator>tim</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[jgroups]]></category>

		<guid isPermaLink="false">http://tim.littlebluefrog.com/?p=632</guid>
		<description><![CDATA[I&#8217;ve spent the day in a frustrating battle with JGroups trying to get it to create all its internal threads as Daemons, rather than user threads. For those that don&#8217;t know, when only Daemon threads are left active, the JVM will shutdown, which is precisely the behavior I required.
Unfortunately, getting JGroups to do this isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the day in a frustrating battle with <a href="http://www.jgroups.org">JGroups</a> trying to get it to create all its internal threads as Daemons, rather than user threads. For those that don&#8217;t know, when only Daemon threads are left active, the JVM will shutdown, which is precisely the behavior I required.</p>
<p>Unfortunately, getting JGroups to do this isn&#8217;t as easy as it really should be. It appears from traffic on their issue tracker that they&#8217;ve gone back on forth on the idea of making all threads Daemon by default or not. Suffice to say at this point in time, they default to user threads.</p>
<p>To save anyone else some pain in trying to figure out what is going on, I&#8217;ve included the code necessary to get JGroups using Daemon threads. It took me a while to figure it out, but I got there in the end. Further, if it wasn&#8217;t for the open source nature of JGroups I would not have been able to figure this out (or perhaps it would have taken much longer). Being able to trawl through source code really is a wonderful thing.</p>
<p>Anyway, here is the code. Remember to set both the ThreadFactory *AND* the ThreadPool. When JGroups creates its internal components on creation of a channel, it creates both the default factory and pool. However, when you set the factory, it doesn&#8217;t also set the pool, so if you only change the factory then the pool still has a link to the initial, default factory. I will submit a patch for this as it seems logical that any change to the factory should trigger a change to the pool as well.</p>
<pre source="java">
JChannel channel = new JChannel(...);

// create a thread factory that will use daemons
DefaultThreadFactory factory =
	new DefaultThreadFactory( Util.getGlobalThreadGroup(),
	                          "Incoming",
	                          true,
	                          true );

// set the thread factory on the transport
channel.getProtocolStack().getTransport().setThreadFactory( factory );

// set the thread pools on the transport
LinkedBlockingQueue&lt;Runnable&gt; queue = new LinkedBlockingQueue&lt;Runnable&gt;();
Executor pool = new ThreadPoolExecutor( 2,
                                        10,
                                        5000,
                                        TimeUnit.MILLISECONDS,
                                        queue,
                                        factory );
channel.getProtocolStack().getTransport().setDefaultThreadPool( pool );
</pre>
<p><b>UPDATE:</b> I&#8217;ve just checked out the latest code from CVS and this problem appears to be fixed there. I&#8217;m running version 2.6.3.GA. So if you are having this problem and using that version or earlier, the above code should help you. If you are using a later version, well, you shouldn&#8217;t be having this problem <img src='http://tim.littlebluefrog.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://tim.littlebluefrog.com/archives/632/feed</wfw:commentRss>
		</item>
		<item>
		<title>Quality and Perception</title>
		<link>http://tim.littlebluefrog.com/archives/625</link>
		<comments>http://tim.littlebluefrog.com/archives/625#comments</comments>
		<pubDate>Fri, 01 Aug 2008 16:46:44 +0000</pubDate>
		<dc:creator>tim</dc:creator>
		
		<category><![CDATA[jarti]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[nerdling]]></category>

		<category><![CDATA[build systems]]></category>

		<category><![CDATA[portico]]></category>

		<guid isPermaLink="false">http://tim.littlebluefrog.com/?p=625</guid>
		<description><![CDATA[Today I read an interesting article that defines &#8220;software quality&#8221; as a function of thought and reflection rather than purely measurable metrics such as the number of passing unit tests. This sentiment resonates quite clearly with me and especially so over the past month. In this time I&#8217;ve been assigned to work on a legacy [...]]]></description>
			<content:encoded><![CDATA[<p>Today I read <a href="http://www.infoq.com/news/2008/06/Unit-Testing-Silver-Bullet">an interesting article</a> that defines &#8220;software quality&#8221; as a function of thought and reflection rather than purely measurable metrics such as the number of passing unit tests. This sentiment resonates quite clearly with me and especially so over the past month. In this time I&#8217;ve been assigned to work on a legacy codebase of significant size, scope and complexity. I have been struggling. The experience thus far has left me feeling somewhat lost, helpless, unproductive and worst of all, like I&#8217;m providing little of any real value.</p>
<p>While I have no doubt of the value that exists in the legacy project, or the quality of its contents, I have found myself cursing it many, many times. Outwardly it would seem that I hold some form of contempt for the project, or the <i>quality</i> of the project, however, that notion this is more assuredly not true. The biggest problem this project has is its build system. While understanding the design and implementation of this large system is difficult enough, it often feels like a developer is actively engaging in a fight with the build system just to compile or package the application or part therein.</p>
<p>This experience has driven home a particular points to me: Although much thought and consideration may be evident in the architecture and design of the product, the same standard hasn&#8217;t been applied to the build system itself. A simple build system is fundamental to the experience of developing for a project. The most amazingly elegant, well designed application can be made to feel unstable, unpredictable and generally brittle if the process used to build it is unnecessary complex and convoluted. </p>
<p>Like most commercial environments, this product was developed under real-world pressures and deadlines. Taking time out to focus exclusively on the build system is difficult to justify when the reality is that it adds no direct features of any value for the end user. However, it has been my experience that neglecting these aspects of a system always ends up costing you time and/or money in the end. To go from a clean windows install to a fully functional development environment for this project took <b>3 entire days</b>. The process involved many, many manual steps, the location, download and installation of countless dependencies, a great many problems with version mismatches for these dependencies and considerable assumptions being made about the level of exposure developers had to particular tools. </p>
<p>In <a href="http://porticoproject.org">Portico</a> we spent a <b>LOT</b> of time working on the build. When significant changes were made to the project (such as adding a C++ interface that required building C++ code), the effect on the build was considered and a lot of thought, time and effort was expended to make sure we had a process that was both easy to use and required the user have the only the bare minimum environment previously installed (just Java and a C++ compiler). This often involved many iterations and on several occasions we had to throw away significant parts of the existing build, replacing them with something that better suited the problem at hand.</p>
<p>Although we could have spent less time and still come up with something that <i>&#8220;worked&#8221;</i>, the task was deemed of such high importance that the extra time and effort seemed justifiable. After all, developers would be interacting with this build day-in and day-out. Yes, it cost time, and by extension it cost my employers money. However, the payoff is immediately obvious. The setup time for a new developer is about 15 minutes and involves two steps: 1) checkout from version control, 2) &#8220;./ant sandbox&#8221;</p>
<p>That&#8217;s it. Spending all that time making sure the build was just right translates not only into time saved later on, but to a much more pleasurable development experience. Such a simple build allows a developer to focus on solving problems with the application rather than having to constantly switch mental contexts in order to engage in hand-to-hand combat with the build system. While quality is a function of thought and reflection, the experience of quality extends only as far as the weakest link. If building your software feels like a huge effort that might not even give you what you want at the end, then it doesn&#8217;t matter how good the code is, the experience is going to be bad.</p>
]]></content:encoded>
			<wfw:commentRss>http://tim.littlebluefrog.com/archives/625/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
