Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 35347 invoked from network); 3 Sep 2003 14:27:12 -0000 Received: from unknown (HELO maingate.mkodo.com) (217.158.103.214) by daedalus.apache.org with SMTP; 3 Sep 2003 14:27:11 -0000 Received: from smtp.uk1.mkodo.com (smtp.uk1.mkodo.com [192.168.11.233]) by maingate.mkodo.com (8.11.2/8.11.2) with ESMTP id h83ERCn28279 for ; Wed, 3 Sep 2003 15:27:12 +0100 Received: from mkodo.com (jjwlaptop.uk1.mkodo.com [192.168.11.239]) by smtp.uk1.mkodo.com (8.12.8/8.12.8) with ESMTP id h83ETTR9020536 for ; Wed, 3 Sep 2003 15:29:36 +0100 Message-ID: <3F55FA9C.8060609@mkodo.com> Date: Wed, 03 Sep 2003 15:28:44 +0100 From: Jon Wingfield User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Counting active sessions if server restarts very often References: <3F55F3D4.6060905@active.ch> In-Reply-To: <3F55F3D4.6060905@active.ch> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 >