Tomcat, creating threads

G

Ghost

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

Brooks Hagenow

Ghost said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top