tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Wingfield <jon.wingfi...@mkodo.com>
Subject Re: Counting active sessions if server restarts very often
Date Wed, 03 Sep 2003 14:28:44 GMT
When the session is created add an attribute that implements 
HttpSessionActivationListener. When the server stops the 
sessionWillPassivate method will be called. When the server restarts the 
  sessionDidActivate method will be called. Use those methods in 
conjunction with your HttpSessionListener to control the count.

HTH,

Jon

Christian Hauser wrote:
> Hello list
> 
> I implemented a session counter to count all active sessions. Now I have 
> the problem that because the server is being restarted very often, my 
> static variable activeSessions is always set to 0.
> 
> Is there an other way to implement this? Maybe by saving the variable 
> activeSessions to a session (which is restored when the server has 
> restarted)?
> 
> I'd like to know the previous value (= value before restart) of the 
> active session count when the server has been restarted.
> 
> Thank you in advance for any hint on that.
>   Christian
> 
> Here's my actual code:
> 
> public class SessionCounter implements HttpSessionListener {
>   private static int activeSessions = 0;
>   public synchronized void sessionCreated(HttpSessionEvent event) {
>     activeSessions++;
>   }
> 
>   public synchronized void sessionDestroyed(HttpSessionEvent event) {
>     if (activeSessions > 0) {
>       activeSessions--;
>     }
>   }
> 
>   public static int getActiveSessions() {
>     return activeSessions;
>   }
> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




Mime
View raw message