You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian Hauser <c....@active.ch> on 2003/09/03 15:59:48 UTC
Counting active sessions if server restarts very often
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;
}
}
Re: Counting active sessions if server restarts very often
Posted by Jon Wingfield <jo...@mkodo.com>.
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
>