<?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; sessions</title>
	<atom:link href="http://www.narnio.com/tag/sessions/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>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>
	</channel>
</rss>
