<?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; illegalstateexception</title>
	<atom:link href="http://www.narnio.com/tag/illegalstateexception/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, 04 Feb 2012 18:31:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<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; 2012 <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>
	</channel>
</rss>

