tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bo Xu ...@cybershop.ca>
Subject Re: Active servlet threads?
Date Tue, 16 Oct 2001 18:35:02 GMT
"prs05@prosa.com" wrote:

> Hi!
>   I'd like to know the number of currently active threads of a servlet from within that
very servlet... I don't know if I've explained well: I'd like to make a method that counts
the active threads, to know in a certain moment how many "servlet copies" are running. I'll
use this da<tum to determine if there aren't anyone, and so I can stop the service (or
do anything else) without anyone complaining and without any delay in waiting the other threads
to finish.
>   Is it possible? I tried with Thread.CurrentThread().getThreadGroup().activeCount(),
but it gives me 32, that I guess is the number of the pooled threads, of all the servlet,
not only this very one...
>   may you help me? Thanks!
>    Germano

the following is as a refrence :-)


public class MyServlet extends HttpServlet{
    private static byte[] locker=new byte[0];
    private static int counter;

    public void service(HttpServletRequest req, HttpServletResponse res) throws IOException,
ServletException{
          synchronized(locker){
              counter++;
         }
    }
}



Mime
View raw message