• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get Total session count

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Is there a way to get total number of sessions created, which in turn can give me number of users connected to the server.

Thanks
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to use HttpSessionListener for that.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a sample application on my site that does just this.
http://simple.souther.us
Look for SessionMonitor.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HttpSessionListener Interface you have sessionCreated() and sessionDestroyed().This mesthods are called when the session is created or destroyed.You can use any static variable in the class which will implement HttpSessionListener which will be incremented once in the sessionCreated().So whenever a new session will be created sessionCreated() method will be called which will increment the value of the static variable.Remember to map this listener class in the web.xml.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You spoke about sessionCreated() but what about sessionDestroyed()?
I opened an application in a number of browsers, the number of active sessions increased automatically. But when I closed few browsers, then the number of active sessions did not decrease.
Any idea on what I might be missing?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Closing a browser doesn't destroy the session.

Since HTTP is a stateless protocol, servers have no way of knowing if a browser has left their site, closed, lost an internet connection, etc..

The abandoned sessions will time out eventually and free up any tied up resources. In the sample project I mentioned, the page that shows all the sessions, lists the time that they started, how long it's been since the last hit, and how much longer the session will last if the user doesn't hit the site again. It also shows the last page that was hit.

With this information, it's usually pretty easy to make intelligent decisions about who's really using the site at any given point in time.
 
Shashi Achanta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ben...Your examples were quite useful and informative.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
I have a sample application on my site that does just this.
http://simple.souther.us
Look for SessionMonitor.



I've downloaded and deployed your sample app and tried to run it. It showed the following error in my browser:

500 Servlet Exception
C:\resin\webapps\sessionmonitor\WEB-INF\web.xml:5: unknown element `xsi:schemaLocation'
in web-app

Please advise. thanks
reply
    Bookmark Topic Watch Topic
  • New Topic