• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Total session count  RSS feed

 
rudresh kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to use HttpSessionListener for that.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a sample application on my site that does just this.
http://simple.souther.us
Look for SessionMonitor.
 
paritosh ranjan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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.
 
Shashi Achanta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot Ben...Your examples were quite useful and informative.
 
Alan Yap
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!