- 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
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