tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Counting active sessions if server restarts very often
Date Thu, 04 Sep 2003 15:43:05 GMT

Howdy,
As an aside, regarding the subject of this message, why is your server
restarting very often?

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Bodycombe, Andrew [mailto:andrew.bodycombe@siemens.com]
>Sent: Thursday, September 04, 2003 11:28 AM
>To: 'Tomcat Users List'
>Subject: RE: Counting active sessions if server restarts very often
>
>The sessionWillActivate() method is called every time a session
activates.
>If your sessions are persistent, then each one will be re-activated
when
>the
>server restarts, so this method is called once for each session that
was
>passivated.
>
>One further point I forgot to mention - your SessionActivationListener
must
>be bound to every session, otherwise the sessionWillActivate() and
>sessionDidPassivate() methods will not be called. You can bind the
listener
>inside the sessionCreated() method.
>
>Sorry for the delay, I've just found this email in my 'Drafts' folder.
>
>Regards,
>	Andy
>
>-----Original Message-----
>From: Christian Hauser [mailto:c.hauser@active.ch]
>Sent: 04 September 2003 10:51
>To: Tomcat Users List
>Subject: Re: Counting active sessions if server restarts very often
>
>
>Thank you, Andrew, for your fast reply.
>
>I hope this works, but I still don't undestand what happens when the
>server is restarted when the sessionCount (current active sessions) is
10.
>
>Will sessionWillPassivate() and sessionDidActivate() be called 10
times?
>Why not once? But if they were called once, my count variable would be
1
>instead of 10 after a restart.
>
>Could someone explain me in a few words what happens when the server is
>restarted?
>
>Thanx,
>   Christian
>
>
>Bodycombe, Andrew wrote:
>
>> The easiest way is probably to have a single listener that implements
>both
>> the HttpSessionListener and HttpSessionActivationListener interfaces.
>This
>> has a single count of active sessions.
>>
>> In the sessionCreated() method, increment the count
>> In the sessionDestroyed() method, decrement the count
>> In the sessionDidActivate() method, increment the count
>> In the sessionWillPassivate() method, decrement the count.
>>
>> This should eliminate the need to store anything in the session.
>>
>> Hope this helps
>> 	Andy
>>
>> -----Original Message-----
>> From: Christian Hauser [mailto:c.hauser@active.ch]
>> Sent: 04 September 2003 10:01
>> To: Tomcat Users List
>> Subject: Re: Counting active sessions if server restarts very often
>>
>>
>> Shapira, Yoav wrote:
>>
>>
>>>Howdy,
>>>
>>>
>>>
>>>>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)?
>>>
>>>
>>>This is not a bad idea, and might be the easiest way.  A DB write on
>>>shutdown/read on startup is also an option.
>>
>>
>> To recapitulate: I want to display all active sessions (~ active
users).
>> I use HttpSessionListener and increment a static int field every time
>> sessionCreated is called. Unfortunately the server is restarted very
>> often so I'd like to remember the active sessions by putting them
into
>> the session.
>>
>> But how? Like this?
>>
>> public class SessionCounter implements HttpSessionListener {
>>
>>    public synchronized void sessionCreated(HttpSessionEvent event) {
>>      Integer i =
>> (Integer)event.getSession().getAttribute("session.counter");
>>      if (i == null) {
>>        i = new Integer(0);
>>      }
>>      int activeSessions = i.intValue() + 1;
>>      event.getSession().setAttribute("session.counter",
activeSessions);
>>    }
>>
>>    public synchronized void sessionDestroyed(HttpSessionEvent event)
{
>>      Integer i =
>> (Integer)event.getSession().getAttribute("session.counter");
>>      if (i == null) {
>>        i = new Integer(0);
>>      }
>>      int activeSessions = i.intValue();
>>      if (activeSessions > 0) {
>>        activeSessions--;
>>      }
>>      event.getSession().setAttribute("session.counter",
activeSessions);
>>    }
>>
>>    public static int getActiveSessions() {
>>      return activeSessions;
>>    }
>> }
>>
>>
>> Jon Wingfield gave me the hint to put an object that implements
>> HttpSessionActivationListener as an attribute to the session.
>> But if I do that in the SessionListener#sessionCreated method I have
100
>> of those objects around when 100 concurrent users are using my web
>> application. Does that make any sense?
>> And what should I do when the object implementing
>> HttpSessionActivationListener enters sessionWillPassivate? How do I
save
>> the count of active sessions?
>>
>> Sorry for all those questions, but I'd like to count the sessions
even
>> when the server restarts very often.
>>
>> Thank you for your help,
>>    Christian
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


Mime
View raw message