I am trying to do some thread profiling on a website that consists
almost entirely of JSPs. When I create a thread in my application, I
give it a relevant name.
The problem is, I am seeing other threads that are calling my classes.
Are these threads being created by Tomcat?
The "unknown" threads have names like: Thread-17, Thread-18, etc.
I'm not sure, but I think these threads are being created every time my
JSPs try to access a session. Is there any way to tell where these
threads are coming from? Or, if they are being created by tomcat, can
I tell tomcat to name them something different?
Thanks in advance.
Brooks Hagenow - 01 Jun 2005 08:16 GMT
> I am trying to do some thread profiling on a website that consists
> almost entirely of JSPs. When I create a thread in my application, I
[quoted text clipped - 10 lines]
>
> Thanks in advance.
Yes, Tomcat creates its own threads as do all Java application servers.
Each request is processed on its own thread and the same servlet/JSP
may be used by multiple threads at once.
You may prevent multiple threads from simultaneously accessing a servlet
by implementing SingleThreadModel but that does not prevent the
application server from creating multiple instances of the servlet. If
you have an instance variable in your servlet (bad idea) that acts as a
counter, you may notice when outputting the value that the value starts
to appear random. That would behavior would be caused by each servlet
instance having its own copy of the counter and each request using
different instances of the servlet. Your session is not necessarily
tied to one instance of a servlet.
JavaWorld Article on Thread-Safe Servlets
http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html