<?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>StyleFeeder Tech Blog &#187; java</title>
	<atom:link href="http://blog.tech.stylefeeder.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tech.stylefeeder.com</link>
	<description>Bitheads Invade the Fashion World</description>
	<lastBuildDate>Mon, 02 Nov 2009 17:01:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>final</title>
		<link>http://blog.tech.stylefeeder.com/2009/08/11/final-java-keyword/</link>
		<comments>http://blog.tech.stylefeeder.com/2009/08/11/final-java-keyword/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 18:35:03 +0000</pubDate>
		<dc:creator>Philip Jacob</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.tech.stylefeeder.com/?p=208</guid>
		<description><![CDATA[I saw this blog post referenced on Hacker News today and thought I&#8217;d pounce on one of Stephan&#8217;s opinions, which is that the final keyword in Java shouldn&#8217;t be used except on fields.  I can&#8217;t disagree strongly enough with this.  I first came across this advice in the O&#8217;Reilly Hardcore Java book about [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this <a href="http://beust.com/weblog/archives/000517.html">blog post</a> referenced on <a href="http://news.ycombinator.com/news">Hacker News</a> today and thought I&#8217;d pounce on one of Stephan&#8217;s opinions, which is that the <strong>final</strong> keyword in Java shouldn&#8217;t be used except on fields.  I can&#8217;t disagree strongly enough with this.  I first came across this advice in the O&#8217;Reilly <a href="http://www.stylefeeder.com/i/gyl2n5hy/Hardcore-Java-Paperback">Hardcore Java</a> book about five years ago.  The book dedicates a whole chapter to the final keyword, which initially surprised me &#8211; I didn&#8217;t think that the author could possibly have that much to say about it!  However, the main idea is &#8220;enforced documentation,&#8221; which is an argument that really sold me on the concept.  I find that whenever I see final on a method parameter, a local variable or whatnot, I have one less question about how that object reference will be used, especially when I&#8217;m reading someone else&#8217;s code.  I know that it was the developer&#8217;s intent that the variable in question be assignable or not.  I find this to be immensely helpful.</p>
<p>Stephan&#8217;s argument is that it impacts readability, but I don&#8217;t find that at all.  In fact, we make final part of our cleanup process for our default formatter in our Eclipse setups at <a href="http://www.stylefeeder.com/">StyleFeeder</a>.  Does final help prevent bugs?  Occasionally, yes, but the cases for this are rare enough that I hesitate to put this forth as the main argument in favor of it.</p>
<p>The Perl-ish argument against this is to &#8220;avoid putting bars on the windows&#8221;, since you never know how things may need to be used in the future.  However, that simply doesn&#8217;t hold up as a solid argument 99% of the time.  The two common use cases for sprinkling final into your Java code are on method parameters (which you should normally not be assigning to) and local variables.  In the case of local variables, they are <em>local</em> and the impact of putting final on them is entirely contained within that scope.  I have yet to see a reason why this would yield any unwanted side effects.  Of course, making classes and methods final is a Big Decision and not what I&#8217;m talking about here.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tech.stylefeeder.com/2009/08/11/final-java-keyword/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>To OOME, or not to OOME</title>
		<link>http://blog.tech.stylefeeder.com/2008/09/23/to-oome-or-not-to-oome/</link>
		<comments>http://blog.tech.stylefeeder.com/2008/09/23/to-oome-or-not-to-oome/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 18:15:55 +0000</pubDate>
		<dc:creator>Jason Rennie</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.tech.stylefeeder.com/?p=101</guid>
		<description><![CDATA[&#8220;Hello?  Contegix?&#8221;  &#8220;Good morning.  We&#8217;ve observed an OutOfMemoryError on stylefeeder01.  We&#8217;ve restarted the web application and it seems to be running fine.&#8221;  &#8220;Thanks for taking care of this for us,&#8221; I&#8217;d say.  At this point, I&#8217;d start digging through log files to find out what had happened.
We&#8217;ve certainly had [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Hello?  Contegix?&#8221;  &#8220;Good morning.  We&#8217;ve observed an OutOfMemoryError on stylefeeder01.  We&#8217;ve restarted the web application and it seems to be running fine.&#8221;  &#8220;Thanks for taking care of this for us,&#8221; I&#8217;d say.  At this point, I&#8217;d start digging through log files to find out what had happened.</p>
<p>We&#8217;ve certainly had our share of Java Garbage Collection fun here at StyleFeeder, from heap and PermGen exhaustion, to memory leaks in libraries we&#8217;ve used; we&#8217;ve even been smacked over the head with the poor choice of NewRatio default for the x86-64 platform.  But, these new OOMEs we were seeing seemed especially odd.  The (Hotspot 1.5.0_09) JVM would log a PermGen OOME (&#8221;java.lang.OutOfMemoryError: PermGen space&#8221;), then proceed like normal, running a Full GC shortly thereafter.  The GC log would indicate that, yes, PermGen was temporarily full, but, no, there was no real lack of space&#8212;the Full GC had no trouble clearing up over half of the available PermGen space.  It was almost as if the JVM was yelling for help before it even tried to clean up its own mess.</p>
<p>At this point, we were using the default server GC, the throughput parallel collector.  The parallel collector has two types of cleanups: scavenges and Full GCs.  When the young generation fills up, a scavenge is fired off, cleaning up the young generations of the heap.  When the old generation or permanent generations fill up, a Full GC is run, which cleans up all memory areas under GC control.  Or, at least, that&#8217;s my understanding of what&#8217;s supposed to happen.  In our case, when the permanent generation filled up, the GC would first fire off an OOME, then run a Full GC.</p>
<p>This smelled like a bug in the JVM.  We weren&#8217;t using the latest version of Hotspot and were a little hesitant to upgrade, so we tried something different: the mark and sweep garbage collector.  We had been thinking about using mark and sweep to avoid the occasional long pauses that are characteristic of the parallel collector.  So, we gave it a whirl, making sure to turn on the options that would do as much permanent generation cleaning as possible:<br />
<code><br />
-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled<br />
</code><br />
We waited&#8230; and waited&#8230; and waited&#8230;  At this point, it&#8217;s been three weeks without an OOME, so I think we can safely declare the change a success.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tech.stylefeeder.com/2008/09/23/to-oome-or-not-to-oome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modified in the Past, Previously Known as the Future</title>
		<link>http://blog.tech.stylefeeder.com/2008/08/13/modified-in-the-past-previously-known-as-the-future/</link>
		<comments>http://blog.tech.stylefeeder.com/2008/08/13/modified-in-the-past-previously-known-as-the-future/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 21:13:59 +0000</pubDate>
		<dc:creator>Jason Rennie</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.tech.stylefeeder.com/?p=28</guid>
		<description><![CDATA[Commons Configuration is a huge timesaver&#8212;flexible, simple configuration management with the highly useful feature of automatic file reloading.  But, lately, that highly useful feature hadn&#8217;t been working for me.  I&#8217;d make a change to the config file in a deployed application and see no change to the values in the application.  WTF? [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://commons.apache.org/configuration/">Commons Configuration</a> is a huge timesaver&#8212;flexible, simple configuration management with the highly useful feature of automatic file reloading.  But, lately, that highly useful feature hadn&#8217;t been working for me.  I&#8217;d make a change to the config file in a deployed application and see no change to the values in the application.  WTF?  What&#8217;s crazy is that it&#8217;d be inconsistent&#8212;some days it would work, others it wouldn&#8217;t.  Yesterday the problem came to a head&#8212;I needed the reloading functionality to work, but it just wasn&#8217;t happening.  So, I put together some simple test code and, viola, it worked!  Huh?  Back to the deployed application: no workie.  Back to the test case: works like a charm.  Egad!</p>
<p>Some JavaDoc digging led me to realize that the problem might be something screwy with the file last modification times.  Sure enough, some of the deployed config file unix mtimes were in the future.  Digging into the Commons code revealed that a file is only reloaded if the current mtime is ahead of the initial mtime of the file.  So, Configuration wouldn&#8217;t reload the file until the present had caught up with the future.  Ack!  But, where were these future timestamps coming from?  Ah, of course&#8230; (with gritted teeth) <a href="http://maven.apache.org/">Maven</a>.  Turns out that the Maven packaging process was storing UTC timestamps in the war file.  Yet, when we exploded the war file using unzip, those timestamps were not converted back to our local (EDT) time, so any file modified around the time of the packaging ended up 4 hours in the future.</p>
<p>The solution turned out to be simple: export TZ=&#8221;America/New_York&#8221;.  This caused maven to store our local, rather than UTC times.  Unzip&#8217;s behavior was unaffected by the setting of TZ, so the deployed files had the correct timestamps after all.  A little test clarifies why Maven is doing this.  Maven uses java code to perform the packaging and the java File.lastModified() method returns the UTC timestamp.  What&#8217;s a bit appalling is that my local timezone is specified on my local system in the usual way: via /etc/localtime.  Basic unix utilities like ls, stat and unzip don&#8217;t seem to have any problem doing the conversion.  But, I don&#8217;t think Maven can be blamed since it&#8217;s probably doing the reasonable thing and using java.util.TimeZone.getDefault() to determine the time zone.  A bit of searching reveals that the blame lays squarely on Sun&#8217;s head for using a poor hack to determine timezone on Linux.  Amazingly, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6456628">the bug describing this problem has been outstanding for over two years</a>.  Sun, is it really that hard to parse an /etc/localtime file?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tech.stylefeeder.com/2008/08/13/modified-in-the-past-previously-known-as-the-future/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
