Threading issue in servlets

Discussions

Web tier: servlets, JSP, Web frameworks: Threading issue in servlets

  1. Threading issue in servlets (1 messages)

    Hi All,
           Can anybody help me to clear this doupt
       The Servlet container uses the servlet thread for servicing each client request but while writing the servlet code we neither implement the Runnable interface nor extend the Thread class then how the servlet container
    can generate the pool of threads?
    Thanks in advance
    bye
    Rama
  2. I can't say I know the exact architecture, but I'd suggest that your servlet is invoked by another object that is already running on a thread. In a manner of speaking, your servlet 'inherits' the thread of the object that invokes it. The object that invokes your servlet is under the control of the server, not you.

    However, you can force the server to allocate one instance of your servlet per thread rather than sharing the same instance among multiple threads. You'd do this if the servlet or JSP you had written was not thread safe. To accomplish this with servlets, they must implement the javax.servlet.SingleThreadModel interface. In JSP's, you add the JSP directive <%@ page isThreadSafe="false" %>.

    Gordon.