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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to