W3C home > Mailing lists > Public > www-jigsaw@w3.org > March to April 2000

Re: Number of users logged

From: Yves Lafon <ylafon@w3.org>
Date: Fri, 3 Mar 2000 11:42:28 +0100 (MET)
To: Wes Biggs <wes@cacas.org>
cc: Walter do Valle <walter@softplan.com.br>, www-jigsaw@w3.org
Message-ID: <Pine.GSO.4.21.0003031137410.18573-100000@tarantula.inria.fr>
On Thu, 2 Mar 2000, Wes Biggs wrote:

> If you want the number of concurrent requests to a particular servlet, I
> would suggest you declare it as an application-scope variable.  At the
> beginning of your service method, increment a counter, at the end,
> decrement it:
> 
> ServletContext application = getServletContext();
> Integer count = null;
> synchronized (application) {
>   count = (Integer) application.getAttribute("countMyServlet");
>   if (count == null) count = new Integer(1);
>   else count = new Integer(count.intValue() + 1);
>   application.setAttribute("countMyServlet", count);
> }
>  // bulk of service()/doGet()/doPost() here
> synchronized (application) {
>   count = new Integer(count.intValue() - 1);
>   application.setAttribute("countMyServlet", count);
> }
> 
> I would put the decrement operation in a finally {} clause to be safe.

Of course, you have to set the lifetime (Servlet Timeout) of the servlet
to -1 to avoid the reset of the servlet!

Another way would be to add a CounterFilter to the frame of the servlet,
but it is related to Jigsaw, so you have to find a way to pass it to the
servlet, by extending CounterFilter.

      /\          - Yves Lafon - World Wide Web Consortium - 
  /\ /  \        Architecture Domain - Jigsaw Activity Leader
 /  \    \/\    
/    \   /  \   http://www.w3.org/People/Lafon - ylafon@w3.org    
Received on Friday, 3 March 2000 05:42:51 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:14:06 UTC