Tomcat, creating threads

Discussion in 'Java' started by Ghost, May 31, 2005.

  1. Ghost

    Ghost Guest

    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.
    Ghost, May 31, 2005
    #1
    1. Advertising

  2. Ghost wrote:
    > 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
    Brooks Hagenow, Jun 1, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Bala

    Tomcat and excessive threads

    Don Bala, Jul 21, 2003, in forum: Java
    Replies:
    0
    Views:
    419
    Don Bala
    Jul 21, 2003
  2. yoda
    Replies:
    2
    Views:
    420
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    384
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,404
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    132
    Une bévue
    Jun 14, 2006
Loading...

Share This Page