<?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>Narnio&#187; java</title>
	<atom:link href="http://www.narnio.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.narnio.com</link>
	<description>A day in the life of a software engineer</description>
	<lastBuildDate>Sat, 28 Aug 2010 16:18:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MSAccess and a really weird behaviour with distinct</title>
		<link>http://www.narnio.com/2010/06/25/msaccess-and-a-really-weird-behaviour-with-distinct/</link>
		<comments>http://www.narnio.com/2010/06/25/msaccess-and-a-really-weird-behaviour-with-distinct/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 06:56:54 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[General Rant]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[MS Access]]></category>

		<guid isPermaLink="false">http://www.narnio.com/2010/06/25/msaccess-and-a-really-weird-behaviour-with-distinct/</guid>
		<description><![CDATA[Recently I started working with MS Access databases, I know not the best choice. I ran into a really weird problem with the database, which I didn&#8217;t expect.
I have a relativly simple select query which contains a distinct. Something like &#8220;select distinct id, content from table&#8221;. Nothing fancy so you&#8217;d expect the content of the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started working with MS Access databases, I know not the best choice. I ran into a really weird problem with the database, which I didn&#8217;t expect.</p>
<p>I have a relativly simple select query which contains a distinct. Something like &#8220;select distinct id, content from table&#8221;. Nothing fancy so you&#8217;d expect the content of the table excluding all duplicates.</p>
<p>But this is also where the weirdness begins with MS Access. I was using this type of query to select data for my search engine. But some data wasn&#8217;t included for some reason.</p>
<p>After a lot of debugging my queries and code it turned out that MS Access ODBC was only returning the first 255 characters of a MEMO field. So I thought the driver was to blame, until I ran the same query in MS Access itself. As it turns out Access was the one truncating MEMO fields to VARCHAR(255) fields when using a DISTINCT in a query.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2010/06/25/msaccess-and-a-really-weird-behaviour-with-distinct/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling Tomcat using Ant scripting</title>
		<link>http://www.narnio.com/2010/05/26/controlling-tomcat-using-ant-scripting/</link>
		<comments>http://www.narnio.com/2010/05/26/controlling-tomcat-using-ant-scripting/#comments</comments>
		<pubDate>Wed, 26 May 2010 16:31:34 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=404</guid>
		<description><![CDATA[As a Java webdeveloper you are faced with a lot of different aspects of development. One is testing and debugging code, to do this you need an application server like Tomcat. One of the issues I recently encountered was the need to control various Tomcat instances with a single Ant build script. Below are some [...]]]></description>
			<content:encoded><![CDATA[<p>As a Java webdeveloper you are faced with a lot of different aspects of development. One is testing and debugging code, to do this you need an application server like Tomcat. One of the issues I recently encountered was the need to control various <a href="http://tomcat.apache.org" target="_blank" title="Tomcat Homepage">Tomcat</a> instances with a single <a href="http://ant.apache.org" target="_blank" title="Ant homepage">Ant</a> build script. Below are some of the solutions I&#8217;ve used to manipulate Tomcat.</p>
<p><b>Note:</b> some parts of this script rely on the <a href="http://ant-contrib.sourceforge.net/" target="_blank" title="Ant Contrib home page">ant-contrib</a> library. Download this library and include it in the tomcat.xml with the following code:</p>
<pre class="brush: xml">
&lt;taskdef resource=&quot;net/sf/antcontrib/antcontrib.properties&quot;&gt;
 &lt;classpath&gt;
  &lt;pathelement location=&quot;./ant-contrib-1.0b3.jar&quot;/&gt;
 &lt;/classpath&gt;
&lt;/taskdef&gt;
</pre>
<h2>Starting tomcat</h2>
<p>Though starting tomcat may seem easy. You could just use the development IDE (like Netbeans) to start and stop Tomcat, but what this lacks is the ability to control several instances with easy shortcuts. So I defined the following Ant <a href="http://ant.apache.org/manual/CoreTasks/macrodef.html" target="_blank" title="Macrodef Documentation">macrodef</a> in a file called tomcat.xml:</p>
<pre class="brush: xml">
&lt;macrodef name=&quot;tomcat-start&quot;&gt;
 &lt;sequential&gt;
   &lt;trycatch&gt;
    &lt;try&gt;
      &lt;if&gt;
       &lt;not&gt;&lt;http url=&quot;http://localhost&quot;/&gt;&lt;/not&gt;
       &lt;then&gt;
         &lt;java classname=&quot;org.apache.catalina.startup.Bootstrap&quot;
             fork=&quot;yes&quot;
             dir=&quot;${tomcat.dir}&quot;
             spawn=&quot;true&quot;
             jvm=&quot;${tomcat.java.home}/bin/java&quot;&gt;
          &lt;jvmarg value=&quot;-Dcatalina.home=${tomcat.dir}&quot;/&gt;
          &lt;jvmarg value=&quot;-Dcatalina.base=${tomcat.dir}&quot;/&gt;
          &lt;jvmarg value=&quot;-Djava.io.tmpdir=${tomcat.dir}/temp&quot;/&gt;
          &lt;jvmarg value=&quot;-Djava.endorsed.dirs=${tomcat.dir}/common/endorsed&quot;/&gt;
          &lt;jvmarg value=&quot;-Xdebug&quot;/&gt;
          &lt;jvmarg value=&quot;-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n&quot;/&gt;
          &lt;classpath&gt;
           &lt;pathelement location=&quot;${tomcat.java.home}/lib/tools.jar&quot;/&gt;
           &lt;pathelement location=&quot;${tomcat.dir}/bin/bootstrap.jar&quot;/&gt;
          &lt;/classpath&gt;

          &lt;arg line=&quot;start&quot; /&gt;
         &lt;/java&gt;

         &lt;waitfor maxwait=&quot;10&quot; maxwaitunit=&quot;second&quot; checkevery=&quot;5000&quot;&gt;
          &lt;http url=&quot;http://localhost&quot;/&gt;
         &lt;/waitfor&gt;
         &lt;echo message=&quot;Tomcat started&quot;/&gt;
       &lt;/then&gt;
       &lt;else&gt;
        &lt;echo message=&quot;Tomcat already started...&quot; /&gt;
       &lt;/else&gt;
     &lt;/if&gt;
    &lt;/try&gt;
    &lt;catch&gt;
     &lt;echo message=&quot;Unable to start tomcat&quot;/&gt;
    &lt;/catch&gt;
  &lt;/trycatch&gt;
 &lt;/sequential&gt;
&lt;/macrodef&gt;
</pre>
<p>This macro is really easy. First it starts of by checking if tomcat is not already running (well actually it just checks to see if there is something running on port 80). If nothing is running then tomcat is started using the java defined by the <a href="http://ant.apache.org/manual/CoreTasks/property.html" title="Property Task documentation" target="_blank">ant property</a> <i>tomcat.java.home</i>. This macro also depends on some other properties that are set by a different macro, which will be a bit further on in the post. Tomcat is started by using the Bootloader class provided by the server, to make sure it loads correctly the <strong>classpath</strong> is set.</p>
<p>The last step in the macro is to wait for tomcat to start, this has to be done since we start tomcat in a seperate java instance (the <i>spawn</i> option).</p>
<h2>Stopping Tomat</h2>
<p>Off course you also want to be able to stop tomcat to load some new data, or an entire web-app. I use the following macro to stop Tomcat:</p>
<pre class="brush: xml">
&lt;macrodef name=&quot;tomcat-stop&quot;&gt;
 &lt;sequential&gt;
  &lt;trycatch&gt;
   &lt;try&gt;
    &lt;java classname=&quot;org.apache.catalina.startup.Bootstrap&quot;
         fork=&quot;yes&quot;
         dir=&quot;${tomcat.dir}&quot;
         spawn=&quot;true&quot;
         jvm=&quot;${java.home}/bin/java&quot;&gt;
     &lt;jvmarg value=&quot;-Dcatalina.home=${tomcat.dir}&quot;/&gt;
     &lt;jvmarg value=&quot;-Dcatalina.base=${tomcat.dir}&quot;/&gt;
     &lt;jvmarg value=&quot;-Djava.io.tmpdir=${tomcat.dir}/temp&quot;/&gt;
     &lt;classpath&gt;
      &lt;pathelement location=&quot;${tomcat.java.home}/lib/tools.jar&quot;/&gt;
      &lt;pathelement location=&quot;${tomcat.dir}/bin/bootstrap.jar&quot;/&gt;
     &lt;/classpath&gt;

     &lt;arg line=&quot;stop&quot; /&gt;
    &lt;/java&gt;

    &lt;kill-java name=&quot;Bootstrap&quot; /&gt;
    &lt;echo message=&quot;Tomcat stopped&quot; /&gt;
   &lt;/try&gt;
   &lt;catch&gt;
    &lt;echo message=&quot;Unable to stop tomcat forcing shutdown.....&quot;/&gt;
    &lt;kill-java name=&quot;Bootstrap&quot; /&gt;
   &lt;/catch&gt;
  &lt;/trycatch&gt;
 &lt;/sequential&gt;
&lt;/macrodef&gt;
</pre>
<p>Just like with the starting of Tomcat I use the provided Bootloader class to instruct tomcat to stop. Again I use the java that is set in <i>tomcat.java.home</i> as well as some other properties loaded by another macro. Since Tomcat sometimes fails to stop gracefully (due to poorly designed webapps) you also have to kill the Java process of Tomcat. This is done with the call to <b>kill-java</b>.</p>
<h2>Killing any java process</h2>
<p>As you saw in the <b>tomcat-stop</b> macro I used a macro called <i>kill-java</i> to make sure that Tomcat is really killed and no longer running in the background. The macro is as follows:</p>
<pre class="brush: xml">
&lt;macrodef name=&quot;kill-java&quot;
          description=&quot;Forcefully stop tomcat....&quot;&gt;
 &lt;attribute name=&quot;name&quot;/&gt;
 &lt;sequential&gt;
  &lt;!-- Execute the jps and check for any Java process with the provided @{name} attribute --&gt;
  &lt;exec executable=&quot;${tomcat.java.home}/bin/jps&quot; output=&quot;pid.out.file&quot; /&gt;
  &lt;!-- Load in the name / pid file and strip all information except the PID --&gt;
  &lt;loadfile srcfile=&quot;pid.out.file&quot; property=&quot;pid.out&quot;&gt;
   &lt;filterchain&gt;
     &lt;linecontains&gt;
      &lt;contains value=&quot;@{name}&quot;/&gt;
     &lt;/linecontains&gt;
    &lt;tokenfilter&gt;
    &lt;deletecharacters chars=&quot;@{name}&quot;/&gt;
    &lt;trim/&gt;
    &lt;ignoreblank/&gt;
    &lt;/tokenfilter&gt;
    &lt;striplinebreaks/&gt;
   &lt;/filterchain&gt;
  &lt;/loadfile&gt;
  &lt;echo message=&quot;Killing java process with pid ${pid.out}&quot;/&gt;
  &lt;!-- Kill the process, warning this only Works on Windows --&gt;
  &lt;exec spawn=&quot;true&quot; executable=&quot;taskkill&quot;&gt;
   &lt;arg line=&quot;/PID ${pid.out}&quot; /&gt;
   &lt;arg line=&quot;/F&quot; /&gt;
  &lt;/exec&gt;
  &lt;delete file=&quot;pid.out.file&quot; /&gt;
 &lt;/sequential&gt;
&lt;/macrodef&gt;
</pre>
<p>This macro is really simple and relies on the jps application provided by Java. This application returns a list of all running processes with name and process id (PID). All we need to do is get the line containing the process name provided and strip everything except the PID.</p>
<p><b>Please note:</b> the task killing the proces is designed for Windows, you could change this with kill in Linux.</p>
<h2>Rounding it up</h2>
<p>Though you now have all you need to manipulate tomcat there is one last macro that we are tegenkant upon. That is the initializer of the various Tomcat properties. I use the following macro:</p>
<pre class="brush: xml">
&lt;macrodef name=&quot;tomcat-init&quot;&gt;
 &lt;attribute name=&quot;from&quot;/&gt;
 &lt;sequential&gt;
  &lt;property name=&quot;tomcat.dir&quot; value=&quot;${tomcat.@{from}.dir}&quot;/&gt;
  &lt;property name=&quot;tomcat.server&quot; value=&quot;${tomcat.@{from}.server}&quot;/&gt;
  &lt;property name=&quot;tomcat.port&quot; value=&quot;${tomcat.@{from}.port}&quot; /&gt;
  &lt;property name=&quot;j2ee.server.type&quot; value=&quot;${tomcat.server}&quot; /&gt;
  &lt;taskdef name=&quot;webapp-stop&quot;
          classname=&quot;org.apache.catalina.ant.StopTask&quot;
          classpath=&quot;${tomcat.dir}/server/lib/catalina-ant.jar&quot;/&gt;
  &lt;taskdef name=&quot;webapp-start&quot;
           classname=&quot;org.apache.catalina.ant.StartTask&quot;
           classpath=&quot;${tomcat.dir}/server/lib/catalina-ant.jar&quot;/&gt;
 &lt;/sequential&gt;
&lt;/macrodef&gt;
</pre>
<p>This little macro will initialize tomcat for a specific environment (for exemple DEV). Of course none of this works without the loading of some preset properties in a property file <i>tomcat.properties</i>. Which contains the following data:</p>
<pre class="brush: php">
tomcat.java.home=C:/jdk1.5.0_22_32b

tomcat.DEV.dir=d:/jakarta/tomcat5.0
tomcat.DEV.server=tomcat55-DEV
tomcat.DEV.port=8000

tomcat.MAIN.dir=d:/jakarta/tomcat5.0-MAIN
tomcat.MAIN.server=tomcat55-MAIN
tomcat.MAIN.port=8000
</pre>
<p>To load the property file just include the following instruction in the build script:</p>
<pre class="brush: xml">
&lt;property file=&quot;./tomcat.properties&quot; /&gt;
</pre>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2010/05/26/controlling-tomcat-using-ant-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans 6.5 Final Release</title>
		<link>http://www.narnio.com/2008/12/05/netbeans-65-final-release/</link>
		<comments>http://www.narnio.com/2008/12/05/netbeans-65-final-release/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 10:47:47 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=230</guid>
		<description><![CDATA[A short while back I wrote a quick review on the beta of Netbeans 6.5 and that it had some issues. Since the final version was released some time ago I thought it was time for a new review. This time of the final version.
The reason for me not to write one straight away was [...]]]></description>
			<content:encoded><![CDATA[<p>A short while back I wrote a quick review on the beta of Netbeans 6.5 and that it had some issues. Since the final version was released some time ago I thought it was time for a new review. This time of the final version.</p>
<p>The reason for me not to write one straight away was simple, I first wanna play around a little to find all the pleasant features and those less pleasant ones.</p>
<h3>Bigger, better, best</h3>
<p>The first thing you expect is this new version to be bigger, better and the best one yet. Well it is bigger in size, with 190MiB for just Java development. So this means a lot more time downloading, but hey that&#8217;s a one time thing.</p>
<p>So lets move onto something more relevant. Is it better then Netbeans 6.1. Lets summorize some of the issues I had with the previous version and see if the problem is solved:</p>
<ol>
<li>It crashed when working on larger projects. This issue has been fixed, netbeans won&#8217;t crash or hang. Though on occasion the parser may crash. Disabling autocomplete and syntax checking.</li>
<li>For some reason previous versions had difficulty displaying the names of parameters when using Java libraries. For as far as I&#8217;ve been able to determine this has been solved.</li>
<li>The autocomplete completely fails in some more complicated web projects. Well I&#8217;m sorry to say this is still true. For some projects not only does autocomplete fail, but so does the syntax checker, both for the JSP files as well as the Java Source files.</li>
</ol>
<p>So are there any other changes that would make you consider moving from Netbeans 5.5 to 6.5?</p>
<h3>New stuff you will like in Netbeans 6.5</h3>
<p>Well have there been any changes that would make you wanna switch to the new version.</p>
<ul>
<li>The new version actually has some basic debugging integrated of JavaScript. Though I haven&#8217;t got it working yet.</li>
<li>PHP development is now support. Which is a big plus, but it still kinda feels like a cheap addon that doesn&#8217;t work perfectly yet. (Maybe in the next release)</li>
<li>Thread debugging has been improved and made easier</li>
</ul>
<p>Unfortunattely not all is good in the world of Netbeans. There are also some new bugs, some of which are really annoying.</p>
<ul>
<li>For some unexplainable reason adding of libraries by right clicking the &#8216;Libraries&#8217; in the project view doesn&#8217;t work all the time.</li>
<li>Like I stated earlier the code completion fails in some of the older Java project I&#8217;m working on. Not only does code completion fail, but the syntax checker tells me every single line is wrong. Even though the project compiles beautifully <img src='http://www.narnio.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
</ul>
<p>As a final note: is it worth upgrading to this version. Then I&#8217;d have to say hell yeah, it&#8217;s a lot better then previous versions. If you are a PHP developer however I suggest not using it, for the moment. Especially when you are already using Zend-Studio, which is still a lot better.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/12/05/netbeans-65-final-release/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Netbeans 6.5 Beta</title>
		<link>http://www.narnio.com/2008/08/16/netbeans-65-beta/</link>
		<comments>http://www.narnio.com/2008/08/16/netbeans-65-beta/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 17:33:43 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General Rant]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=207</guid>
		<description><![CDATA[Since I have to use Netbeans at my work, I always try and find the best version for me. In my case this means a version that runs quickly and is sorta stable. Since the new Netbeans 6.5 beta was released I decided to give it a shot.
First things I was seriously hoping was that [...]]]></description>
			<content:encoded><![CDATA[<p>Since I have to use Netbeans at my work, I always try and find the best version for me. In my case this means a version that runs quickly and is sorta stable. Since the new <a href="http://download.netbeans.org/netbeans/6.5/beta/">Netbeans 6.5 beta</a> was released I decided to give it a shot.</p>
<p>First things I was seriously hoping was that they fixed the bug with Netbeans not recognizing the names of function parameters of libraries. This is a problem which got me so pissed that I switched back from Netbeans 6 to 5.5, which did not have the problem. Both Netbeans 6.0 and <a href="http://download.netbeans.org/netbeans/6.1/final/">Netbeans 6.1</a> had the same problem with function parameters.</p>
<p>Let&#8217;s just say that on this they did not disapoint. The new Beta version has got no issues recognizing the names of function parameters. So that&#8217;s a serious improvement of the previous releases. I also like the new style for debugging and code editing.</p>
<p>The only real issues so far are the fact that with large web applications Netbeans 6.5 constantly hangs and stops responding. Another issue is that the debugger does not highlight the line that it&#8217;s on. The latter is probably a simple fix, but it does make debugging slightly difficult.</p>
<p>So lets wait and see if some of these issues get resolved in the final release.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/08/16/netbeans-65-beta/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To Get An Accurate Session Count With Tomcat</title>
		<link>http://www.narnio.com/2008/07/15/how-to-get-an-accurate-session-count-with-tomcat/</link>
		<comments>http://www.narnio.com/2008/07/15/how-to-get-an-accurate-session-count-with-tomcat/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 18:07:52 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=204</guid>
		<description><![CDATA[Recently we started to notice that even after disabling a server in our loadbalancer we still get traffic on it after two months. At least for as far as we count it. We currenlty count traffic by using the SessionListener to get notification of people leaving and coming, but somehow our counter gets stuck at [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we started to notice that even after disabling a server in our loadbalancer we still get traffic on it after two months. At least for as far as we count it. We currenlty count traffic by using the SessionListener to get notification of people leaving and coming, but somehow our counter gets stuck at about 500 sessions 2 months after switching the server of in the load balancer.</p>
<p>Some time back I already wrote about the setup we use in counting sessions. Read more on that in the <a title="Read the article" href="http://www.narnio.com/2008/05/06/cleaning-up-java-sessions/">&#8216;Cleaning Up Java Sessions&#8217;</a> post. We put live this change some time back. But I&#8217;m still having some issues with the sessions.</p>
<p>What we do is something like this. When a user comes in through a servlet we look if a specific object is set in the session. If not we invalidate the session and add the object. In a seperate class we catch all session starts and destructions.</p>
<p>Upon the session start function in HttpSessionListener we increase the counter. Upon the destruction of the session and if the our session object is set we decrease the counter. But for some reason we have some sessions that do not get cleaned up by Tomcat. Or there are some users that simply stay online for over 2 months.</p>
<p>To get a semi accurate count of the active session I looked into getting the amount of active sessions from the Tomcat <a title="JavaDoc for the StandardManager" href="http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/session/StandardManager.html">StandardManager</a> class. In theory you would be able to obtain this through the tomcat implementation of the HttpSession object. But for some reason these objects are package protected.</p>
<p>There has to be an easier way of getting an accurate count of the amount of active sessions through the tomcat API.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/07/15/how-to-get-an-accurate-session-count-with-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cleaning Up Java Sessions</title>
		<link>http://www.narnio.com/2008/05/06/cleaning-up-java-sessions/</link>
		<comments>http://www.narnio.com/2008/05/06/cleaning-up-java-sessions/#comments</comments>
		<pubDate>Tue, 06 May 2008 17:17:59 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[illegalstateexception]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=194</guid>
		<description><![CDATA[As part of a migration from Resin 1.3 to Tomcat 5 we had to migrate servers that are session based. Because we wanted to measure the time someone was on the website a listener had to be used. In resin this was done by implementing a HttpSessionBindingListener. But when we migrated to tomcat our measurements [...]]]></description>
			<content:encoded><![CDATA[<p>As part of a migration from Resin 1.3 to Tomcat 5 we had to migrate servers that are session based. Because we wanted to measure the time someone was on the website a listener had to be used. In resin this was done by implementing a HttpSessionBindingListener. But when we migrated to tomcat our measurements no longer worked.</p>
<p>Once a session became invalidated the <a title="JavaDoc page on HttpSessionBindingListener" href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpSessionBindingListener.html">HttpSessionBindingListener </a>valueUnbound method was called. During this call we used the getLastAccessedTime() on the session to figure out how long the session was idle before the session was cleaned up.</p>
<p>During the investigation as to why the idle time was no longer logged we found out that for some reason the valueUnbound was no longer working the same in Tomcat as it used to in Resin. After some debuging it appeared as if the HttpSession.<a title="JavaDoc" href="http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpSession.html#getLastAccessedTime()">getLastAccessedTime()</a> could no longer be used at this stage of the clean up. Every time you tried to access it I got a <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalStateException.html">IllegalStateException</a>.</p>
<p>Some searching on the web later toled me that this was because the session is already invalidated at this point. And an invalidated sessions information cannot be trusted. So what I had to do is build another listener. This time one that is more generic and catches all session deletions. The class to implement in order to do this is called the <a title="JavaDoc on SessionListener" href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpSessionListener.html">HttpSessionListener</a>. The methods on this class are called when a session is made or destroyed.</p>
<p>By storing the last access time during the destruction the idle time is available.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/05/06/cleaning-up-java-sessions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why It&#8217;s good to have the directory structure match namespace structure</title>
		<link>http://www.narnio.com/2008/03/02/why-its-good-to-have-the-directory-structure-match-namespace-structure/</link>
		<comments>http://www.narnio.com/2008/03/02/why-its-good-to-have-the-directory-structure-match-namespace-structure/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 11:48:17 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General Rant]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.narnio.com/2008/03/02/why-its-good-to-have-the-directory-structure-match-namespace-structure/</guid>
		<description><![CDATA[Before I dive to deep into a point bullet list as to why this is important let&#8217;s first explain how I got to this point. For the past year or so I&#8217;ve been working in Java. One of the few languages that I know of that automatically creates a new directory for each package created [...]]]></description>
			<content:encoded><![CDATA[<p>Before I dive to deep into a point bullet list as to why this is important let&#8217;s first explain how I got to this point. For the past year or so I&#8217;ve been working in Java. One of the few languages that I know of that automatically creates a new directory for each <a href="http://en.wikipedia.org/wiki/Java_package" target="_blank">package</a> created (similar to C++ <a href="http://en.wikipedia.org/wiki/Namespace_%28programming%29" target="_blank">namespace</a>). If you don&#8217;t pay any attention to it you&#8217;d never even know it does this.</p>
<p>But when you want to look at files in the file explorer you might have some trouble finding the right file, and you may find expanding all the directories annoying (I know I did <img src='http://www.narnio.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Especially when you are browsing the <a href="http://en.wikipedia.org/wiki/Subversion_%28software%29" target="_blank">SVN</a> or <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" target="_blank">CVS</a> when each folder takes forever to load <img src='http://www.narnio.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>As I noted in the first paragraph were over a year further and I must say that I like structuring the folder structure the same as the namespaces in the code. Let me explain why.</p>
<p><strong>Easier to find a class</strong>    <br />Though you may not notice it at first, but it is easier to find a class when the directory structure is similar to that in the source code. After all you already know the namespace it&#8217;s in. So locating the files becomes a lot easier.</p>
<p><strong>You instantly know what classes belong to which namespace</strong>    <br />I don&#8217;t know about all off you but I don&#8217;t always have my projects open when I&#8217;m documenting on <a href="http://en.wikipedia.org/wiki/Trac" target="_blank">trac</a>. So to figure out which classes are part of a namespace I simply open the directory and find out. That way I don&#8217;t have to load the entire project every single time.</p>
<p><strong>Moving of classes to other namespaces becomes easier</strong>    <br />When you come to the point that you need to refactoring having all classes from a namespace in one directory makes it a lot easier to refactor. No longer do you have to open each file to find out in which namespace it&#8217;s located, just look at the directory structure.</p>
<p>This also introduces the downside that you need to move the classes in the SVN or CVS since the namespace has changed, but hey everything has it&#8217;s downsides <img src='http://www.narnio.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>&#160;</p>
<p>Let me know if you now any good reasons, or have some strong reasons against.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/03/02/why-its-good-to-have-the-directory-structure-match-namespace-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
