Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SessionCounter  RSS feed

 
Christian Hauser
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marty and others
I had a problem some time ago and wonder if that could now be implemented better using Servlets 2.4 and JSP 2.0. I needed a session counter that kept track of the active sessions, so that I roughly knew how many users were online.
I implemented a SessionCounter class that implemented HttpSessionListener. On sessionCreated() I incremented a static variable and on sessionDestroyed I decremented the static variable (setting it to 0 when it got negative).
The problem there was the fact that this web server rebooted very often (at least twice a day). After every reboot I lost my static variable (it was reset to 0). However, the sessions had been restored by Tomcat but (of course) I got no sessionCreated() events for those restored sessions... So for at least 2-3 hours (due to a high session timeout) I got a too low count of active users.
Now I would like to know if there is a more reliable solution to this problem using the new Servlet Spec 2.4 or if there are new event listeners.
Thank you for any hint.
Regards,
Christian
[ November 12, 2003: Message edited by: Christian Hauser ]
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One simple solution is to store the counter in the database and restore it whenever the server reboots... For me, I usually do that way to handle the static variables like counters...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!