This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

SessionCounter  RSS feed

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 (high session timeout)
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.
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same issue. I tried using the ContextDestroyed method of the ServletContextListener to save my session counts (in a file for example). Next time when the context is initialized I load the saved counts in the ContextInitialized method of the same listener.

This works for me but not sure if this is the right thing to do.
Author and ninkuma
Posts: 66810
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sreeram L A", please check your private messages.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!