<?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>What I Learned Today &#187; java</title>
	<atom:link href="http://christiansons.net/mike/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://christiansons.net/mike/blog</link>
	<description>Mike Christianson&#039;s journal of Java, Ant, SVN, Jetty, cygwin and other stuff.</description>
	<lastBuildDate>Wed, 04 Aug 2010 22:24:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Sun Java 6 on Ubuntu 10.04 10.10 and later</title>
		<link>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/</link>
		<comments>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 16:17:04 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=512</guid>
		<description><![CDATA[Much to my surprise, but probably not those of the Open Source Ruling Class, Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse. Apparently the Ubuntu folks have started putting some weight behind their recommendations for switching to the &#8220;OpenJDK.&#8221; Fortunately, the official, &#8220;proprietary&#8221; Java is still available through another Ubuntu repository. To make [...]]]></description>
			<content:encoded><![CDATA[<p>Much to my surprise, but probably not those of the Open Source Ruling Class, <a href="https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Sun%20Java%20moved%20to%20the%20Partner%20repository">Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse</a>.  Apparently the Ubuntu folks have started putting some weight behind their recommendations for switching to the &#8220;OpenJDK.&#8221;  Fortunately, the official, &#8220;proprietary&#8221; Java is still available through another Ubuntu repository.</p>
<p>To make Sun&#8217;s Java 6 JDK available on Ubuntu 10.04, 10.10 or later, add the new repository like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">add-apt-repository <span style="color: #ff0000;">&quot;deb http://archive.canonical.com/ lucid partner&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update</pre></div></div>

<p>Then, be sure to follow my previous <a href="http://christiansons.net/mike/blog/2008/11/java-6-update-10-is-available/">instructions for installing the JDK</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Shutting down ehcache properly</title>
		<link>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/</link>
		<comments>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:37:29 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[ehcache]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[shutdownhook]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=422</guid>
		<description><![CDATA[If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to shut down ehcache properly. To do so when using ehcache within a webapp, simply add its ShutdownListener as a listener in web.xml. &#60;listener&#62; &#60;listener-class&#62;net.sf.ehcache.constructs.web.ShutdownListener&#60;/listener-class&#62; &#60;/listener&#62; Alternatively, or when not using ehcache inside a webapp, instruct ehcache [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to <a href="http://ehcache.org/documentation/shutdown.html">shut down ehcache properly</a>.</p>
<p>To do so when using ehcache within a webapp, simply add its <tt>ShutdownListener</tt> as a <tt>listener</tt> in <tt>web.xml</tt>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.sf.ehcache.constructs.web.ShutdownListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Alternatively, or when not using ehcache inside a webapp, instruct ehcache to register its own <a href="http://java.sun.com/developer/TechTips/2000/tt0711.html">shutdown hook</a> by setting a system property.</p>
<pre>net.sf.ehcache.enableShutdownHook=true</pre>
<p>If you forget one of the above, your persisted cache may not be up-to-date, or worse, not persisted at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Advanced Installer licensing within a Java application</title>
		<link>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/</link>
		<comments>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 03:31:34 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[advancedinstaller]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=108</guid>
		<description><![CDATA[Advanced Installer 6.7 has a new licensing and registration feature which allows for time-limited demos/trials and registration of installed software. Caphyon, the maker of Advanced Installer, provides code samples and documentation on licensing integration for C++ and C# applications. To use this feature, the application must make a call into an Advanced Installer library and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.advancedinstaller.com/"><img alt="" src="http://www.caphyon.com/img/index/biglogo_ai.gif" title="Advanced Installer" class="alignleft" width="69" height="99" /></a>Advanced Installer 6.7 has a <a href="http://www.advancedinstaller.com/user-guide/licensing.html">new licensing and registration feature</a> which allows for time-limited demos/trials and registration of installed software.</p>
<p>Caphyon, the maker of Advanced Installer, provides code samples and <a href="http://www.advancedinstaller.com/user-guide/qat-trial.html">documentation on licensing integration</a> for C++ and C# applications.  To use this feature, the application must make a call into an Advanced Installer library and handle its return code.  </p>
<p>The library is a gatekeeper to the rest of the application, effectively deciding whether or not the application is allowed to run.  It determines the software&#8217;s trial status and displays a registration dialog, terminates the application, or returns a code, accordingly.  The Java implementation of this feature works a little differently.</p>
<p>For those using the <a href="http://www.advancedinstaller.com/user-guide/native-java-launcher.html">Java Launcher</a>, integrating the licensing feature is easy: simply add the Java Product on the <a href="http://www.advancedinstaller.com/user-guide/licensing-settings.html">Licensing Options</a> tab.  But, what about those who don&#8217;t use Java Launcher?  Or those that wish to enable users to register from within the application?</p>
<p>There is no official documentation which answers these questions, but based on a discussion following a <a href="http://www.advancedinstaller.com/forums/viewtopic.php?f=2&#038;t=8538">request for help I posted on the Advanced Installer forums</a>, I was able integrate AI&#8217;s licensing feature into my Java application without using the Java Launcher.<span id="more-108"></span></p>
<p>My solution mirrors the C++ implementation and is remarkably simple.  Thanks to Cosmin, a member of the Advanced Installer support team, for sending me in the right direction.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LicenseChecker <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> LIBRARY_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Replace this String with the Trialware/Registration Library Key&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> TrialLibrary.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">ReadSettingsStr</span><span style="color: #009900;">&#40;</span>LIBRARY_KEY, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//http://www.advancedinstaller.com/user-guide/qa-trial-using.html</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for registering this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for trying this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Program will continue.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// ...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">interface</span> TrialLibrary <span style="color: #000000; font-weight: bold;">extends</span> Library <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> TrialLibrary INSTANCE <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TrialLibrary<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">Native</span>.<span style="color: #006633;">loadLibrary</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Trial&quot;</span>, TrialLibrary.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// loads Trial.dll</span>
        <span style="color: #000066; font-weight: bold;">int</span> ReadSettingsStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> DisplayRegistrationStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note: The above uses <a href="https://jna.dev.java.net/">Java Native Access (JNA)</a> to invoke the Advanced Installer library.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GCViewer, garbage collection and heap analysis tool</title>
		<link>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/</link>
		<comments>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 23:46:48 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[gcviewer]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=94</guid>
		<description><![CDATA[One month ago I wrote about the benefits of using Java&#8217;s built-in garbage collection logging.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221; There is, of course, a hitch: for any non-trivial application or [...]]]></description>
			<content:encoded><![CDATA[<p>One month ago I wrote about the benefits of using <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java&#8217;s built-in garbage collection logging</a>.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221;</p>
<p>There is, of course, a hitch: for any non-trivial application or problem, you will be quickly buried by a mountainous log file.  The longer your application runs, the larger the log file.  It keeps growing, and growing, and&#8230;</p>
<div id="attachment_98" class="wp-caption alignright" style="width: 160px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot.png"><img class="size-thumbnail wp-image-98" title="gcviewer-screenshot" src="/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot-150x150.png" alt="GCViewer" width="150" height="150" /></a><p class="wp-caption-text">GCViewer</p></div>
<p>What will you do?  Write a second Java app, one that parses the log file &#8212; attempt a homegrown analysis tool?  No!  Instead, I suggest you use <a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a>, a free open-source tool for visualizing the <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java gc log file</a>.</p>
<p><a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a> helps you get a quick and comprehensive look at how your application is behaving.  Things like total heap vs. heap used and full GC events become very apparent.  Useful statistics such as time spent during GC are calculated for your convenience.</p>
<p>GCViewer is created by <a href="http://www.tagtraum.com/">tagtraum industries</a> and is available under an <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a> license.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SeaFlow, Java app for Seattle traffic conditions</title>
		<link>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 20:41:45 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[seattle]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=64</guid>
		<description><![CDATA[Late in 1999, UltiMeth Systems created SeaFlow, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of WSDOT&#8217;s web-based traffic map.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic. SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_67" class="wp-caption alignleft" style="width: 310px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1.png"><img class="size-medium wp-image-67" title="SeaFlow screenshot" src="/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1-300x179.png" alt="SeaFlow screenshot from Dec. 18, 2008." width="300" height="179" /></a><p class="wp-caption-text">SeaFlow screenshot from Dec. 18, 2008.</p></div>
<p>Late in 1999, <a title="homepage of UltiMeth Systems" href="http://www.ultimeth.com/">UltiMeth Systems</a> created <a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a>, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of <a title="WSDOT Seattle traffic" href="http://www.wsdot.wa.gov/traffic/seattle/">WSDOT&#8217;s web-based traffic map</a>.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic.</p>
<p>SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density which is certainly useful, but not a complete picture.)  The visual color representation of each metric can be customized in SeaFlow.</p>
<p>In times of peak demand, such as <a title="WSDOT blog post for 2008-12-18" href="http://wsdotblog.blogspot.com/2008/12/december-8-2008.html">December 18, 2008</a>, WSDOT&#8217;s website may become overwhelemed and yield partial or missing maps.  SeaFlow&#8217;s use of the smaller WSDOT data file &#8212; with maps rendered on the client-side &#8212; reduces demand on WSDOT&#8217;s site and can provide more reliable and complete updates.</p>
<p><a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a> is a great Java desktop app &#8212; small, efficient, and cross-platform.  Its license is <a title="homepage of GNU GPL" href="http://www.gnu.org/licenses/gpl.html">GPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java garbage collection logging</title>
		<link>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 08:00:56 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=28</guid>
		<description><![CDATA[Java&#8217;s built-in garbage collection logging provides a quick, easy, and free way to profile or troubleshoot your Java application.  It can help you understand your application in terms of: memory usage (object count and size) heap size (initial and over time) GC metrics (frequency, pause time, and amount freed) So, now you can answer questions [...]]]></description>
			<content:encoded><![CDATA[<p>Java&#8217;s built-in garbage collection logging provides a quick, easy, and <em>free</em> way to profile or troubleshoot your Java application.  It can help you understand your application in terms of:</p>
<ul>
<li> memory usage (object count and size)</li>
<li>heap size (initial and over time)</li>
<li>GC metrics (frequency, pause time, and amount freed)</li>
</ul>
<p>So, now you can answer questions like &#8220;how much memory is my app using,&#8221; &#8220;how much time is being spent doing garbage collection,&#8221; and &#8220;how big is the heap over time.&#8221;</p>
<p style="border: thin dashed;">
<em>For help analyzing and visualizing a GC log file, be sure to check out <a href="http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/">GCViewer, a garbage collection and heap analysis tool</a>.</em>
</p>
<p>GC logging is enabled using JVM arguments; below are the arguments I use.  <span id="more-28"></span>(Note: the log file specified as <em>file</em> is reset each time the VM starts.)</p>
<p><code>-verbose:gc -Xloggc:<em>file</em></code></p>
<p>Here&#8217;s an example GC log file which shows three GC events including one full GC.</p>
<pre>[GC 19062K-&gt;7172K(60800K), 0.0087190 secs]
[GC 9346K-&gt;7525K(60800K), 0.0052810 secs]
[Full GC 7525K-&gt;7477K(60800K), 0.0615190 secs]</pre>
<p>In the first event, garbage collection takes just under nine thousandths of a second to collect 11,890K memory used by objects (19,062K to 7,172K) while the heap is 60,800K.  The last event is a full GC lasting just over six hundredths of a second to free up 48K with no change in the heap.</p>
<p>Data like this can be invaluable in saving one&#8217;s sanity or ending arguments! For further details on garbage collection, see Sun&#8217;s <a title="article on GC Portal" href="http://java.sun.com/developer/technicalArticles/Programming/GCPortal/">GC Portal</a> and <a title="doc on GC tuning" href="http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html">Virtual Machine Garbage Collection Tuning</a> documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Jetty, embedded servlet container</title>
		<link>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 21:59:06 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[servlet]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=49</guid>
		<description><![CDATA[There&#8217;s no law which states web servers and servlet containers must be large, separate pieces of software.  If there were, Jetty would be a dangerous outlaw (possibly even public enemy number one).  Jetty is an open-source embeddable web server and servlet container, written in Java.  It&#8217;s small, fast, and easy to embed &#8212; perfect for [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no law which states web servers and servlet containers must be large, separate pieces of software.  If there were, <a title="Jetty website" href="http://www.mortbay.org/jetty/">Jetty</a> would be a dangerous outlaw (possibly even public enemy number one).  Jetty is an open-source embeddable web server and servlet container, written in Java.  It&#8217;s small, fast, and easy to embed &#8212; perfect for self-contained applications.</p>
<p>Let&#8217;s use an example to discover just how easy embedding Jetty can be.  <span id="more-49"></span>Say we have two servlets, one should be mapped to <tt>/service/one</tt> and the other <tt>/service/two</tt>, served on port <tt>8080</tt>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">Server server <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Server<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Connector connector <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SelectChannelConnector<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connector.<span style="color: #006633;">setPort</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8080</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">addConnector</span><span style="color: #009900;">&#40;</span>connector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ContextHandlerCollection contexts <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ContextHandlerCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">setHandler</span><span style="color: #009900;">&#40;</span>contexts<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">Context</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Context</span><span style="color: #009900;">&#40;</span>contexts, <span style="color: #0000ff;">&quot;/service&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #006633;">addServlet</span><span style="color: #009900;">&#40;</span>ServiceOne.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;/one&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #006633;">addServlet</span><span style="color: #009900;">&#40;</span>ServiceTwo.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;/two&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
server.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it; easy.  For information and more examples on embedding Jetty in your Java application, read <a title="wiki documentation on embedding Jetty" href="http://docs.codehaus.org/display/JETTY/Embedding+Jetty">Embedding Jetty</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Remote debugging</title>
		<link>http://christiansons.net/mike/blog/2008/11/remote-debugging/</link>
		<comments>http://christiansons.net/mike/blog/2008/11/remote-debugging/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 22:13:50 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=26</guid>
		<description><![CDATA[I never knew how good life could be &#8212; at work, mind you &#8212; until I spent some quality time with the Eclipse debugger.  My days of relying solely on System.out.println() are long gone.  Print debugging is only useful if you can change the code.  Loggers like Log4j are only marginally better &#8212; assuming the [...]]]></description>
			<content:encoded><![CDATA[<p>I never knew how good life could be &#8212; at work, mind you &#8212; until I spent some quality time with the Eclipse debugger.  My days of relying solely on <a title="Javadoc for System.out" href="http://java.sun.com/javase/6/docs/api/java/lang/System.html#out"><tt>System.out.println()</tt></a> are long gone.  Print debugging is only useful if you can change the code.  Loggers like <a title="Log4j" href="http://logging.apache.org/log4j/1.2/index.html">Log4j</a> are only marginally better &#8212; assuming the code uses it properly in the first place.</p>
<p>And things get more interesting when the code is running on a different or remote machine.  Luckily, Java has a great remote debugging facility. Here&#8217;s an example of how I enable remote debugging using command-line arguments.</p>
<p><code>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</code></p>
<p>In this example, the remote application will start and run normally while listening in the background for a debugger to connect on port 8000.  For further details on how to enable and configure remote debugging, see Sun&#8217;s <a title="JPDA guide" href="http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html">JPDA Connection and Invocation</a> guide.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/11/remote-debugging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remote JMX</title>
		<link>http://christiansons.net/mike/blog/2008/11/remote-jmx/</link>
		<comments>http://christiansons.net/mike/blog/2008/11/remote-jmx/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 21:02:27 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=24</guid>
		<description><![CDATA[The following Java system properties allow unauthenticated and unsecured remote JMX client connections. I use these system properties when remotely troubleshooting problems during development.  My JMX agent of choice is JConsole, part of the JDK. -Dcom.sun.management.jmxremote.port=port -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false For further details on JMX and how to configure access, consult Sun&#8217;s Java JMX Management Guide.]]></description>
			<content:encoded><![CDATA[<p>The following Java system properties allow unauthenticated and unsecured remote JMX client connections. I use these system properties when remotely troubleshooting problems during development.  My JMX agent of choice is <a title="JConsole guide" href="http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html">JConsole</a>, part of the JDK.</p>
<p><code>-Dcom.sun.management.jmxremote.port=<em>port</em><br />
-Dcom.sun.management.jmxremote.authenticate=false<br />
-Dcom.sun.management.jmxremote.ssl=false</code></p>
<p>For further details on JMX and how to configure access, consult Sun&#8217;s Java <a title="JMX Management Guide" href="http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html">JMX Management Guide</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/11/remote-jmx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JScience unit formatting</title>
		<link>http://christiansons.net/mike/blog/2008/11/jscience-unit-formatting/</link>
		<comments>http://christiansons.net/mike/blog/2008/11/jscience-unit-formatting/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 00:45:10 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jscience]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=18</guid>
		<description><![CDATA[JScience uses Unicode characters in the String representations of some of its Units.  For example, Unicode U+2103 (℃) is used to represent the unit for degrees Celsius.  Those characters can cause problems with fonts and/or platforms (Windows, typically) which do not contain or recognize them.  Instead, you may see a question mark, box, or other [...]]]></description>
			<content:encoded><![CDATA[<p><a title="JScience is a Java library for working with scientific measurements." href="http://jscience.org/">JScience</a> uses Unicode characters in the String representations of some of its Units.  For example, Unicode <a title="U-2103" href="http://www.fileformat.info/info/unicode/char/2103/index.htm">U+2103</a> (℃) is used to represent the unit for degrees Celsius.  Those characters can cause problems with fonts and/or platforms (Windows, typically) which do not contain or recognize them.  Instead, you may see a question mark, box, or other unfamiliar glyph.  Here is the symbol for degrees Celsius again &#8212; ℃ &#8212; can you see it properly?</p>
<p>Using <a title="Javadoc for UnitFormat.label()" href="http://jscience.org/api/javax/measure/unit/UnitFormat.html#label(javax.measure.unit.Unit,%20java.lang.String)">UnitFormat.label()</a>, we can override the String representation to something more compatible, useful, or just different.  Here&#8217;s how I changed degrees Celsius to be more compatible with my co-workers Windows systems.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">UnitFormat.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">label</span><span style="color: #009900;">&#40;</span>SI.<span style="color: #006633;">CELSIUS</span>, <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\u</span>00B0&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;C&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And here&#8217;s how I changed knots to be represented by <tt>kts</tt> instead of the default, <tt>kn</tt>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">UnitFormat.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">label</span><span style="color: #009900;">&#40;</span>NonSI.<span style="color: #006633;">KNOT</span>, <span style="color: #0000ff;">&quot;kts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/11/jscience-unit-formatting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
