Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: Session Monitoring tool?

JNeuhoff

2007-01-22

Replies:


You may want to implement your own HTTPSessionListener for your servlet. It
looks something like this:

package mypackage;

import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;

public class SessionListener implements HttpSessionListener {

 static int activeSessions =  0;
 static int maxActiveSessions = 0;

 /** Session Creation  Event */
 public void sessionCreated( HttpSessionEvent se) {
   synchronized (this) {
     activeSessions++;
     if (activeSessions > maxActiveSessions) {
       maxActiveSessions = activeSessions;
     }
   }
 }

 /** Session Invalidation  Event */
 public void sessionDestroyed( HttpSessionEvent se) {
   synchronized(this) {
     if(activeSessions > 0) {
       activeSessions--;
     }
   }
 }

 /** get the number of currently active HTTP sessions */
 public static int getActiveSessions() {
   return activeSessions;
 }

 /** get the maximum active concurrent HTTP sessions used so far */
 public static int getMaxActiveSessions() {
   return maxActiveSessions;
 }

}



In your web.xml, add the following lines to make sure Tomcat sends the
events to your session listener during runtime:

  <!-- Listeners -->
  <listener>
    <listener-class>mypackage.SessionListener</listener-class>
  </listener>


Hope this helps.

J.Neuhoff



Kristian Rink wrote:
>
>
> Folks;
>
> does anyone know of any tomcat tool to watch HTTP sessions which
> are active in any deployed web application (and, best case, data
> assigned to them, aside the session ID itself)? I thought /manager
> or /admin to provide functionality like this but so far I failed to
> find it...
>
> Thanks in advance and bye,
> Kristian
>
>
> --
> Kristian Rink * http://zimmer428.net * http://flickr.com/photos/z428/
> jab: kawazu@(protected)
> "One dreaming alone, it will be only a dream; many dreaming together
> is the beginning of a new reality." (Hundertwasser)
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@(protected)
> To unsubscribe, e-mail: users-unsubscribe@(protected)
> For additional commands, e-mail: users-help@(protected)
>
>
>

--
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.