tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steffen Späthe <stef...@spaethe.net>
Subject Re: multiple, parallel requests
Date Tue, 06 Jun 2006 08:28:52 GMT
 > Maybe you should paste your "simple HttpServlet" code ?

No Problem. Note, there is a "service"-methode in this sample-code. It 
is just for debugging and testing. There is no difference between 
behavior with or without this "service"-methode.

Okay, here is my simple HttpServlet (it is really simple, isn´t it :-) ):

import java.io.*;
import java.net.*;
import java.util.Date;

import javax.servlet.*;
import javax.servlet.http.*;

public class ThreadingTest extends HttpServlet {
   
    protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ThreadingTest</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Start</h1>");
        out.flush();
       
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {}

        out.println("<h1>Ready</h1>");
        out.println("</body>");
        out.println("</html>");
        out.close();
    }
   
    protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    protected void doPost(HttpServletRequest request, 
HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    public String getServletInfo() {
        return "Short description";
    }


    public void service(ServletRequest req, ServletResponse res) throws 
ServletException, IOException {
        System.out.println(System.currentTimeMillis() +"ThreadingTest 
invoke service... "  + Thread.currentThread().toString());
        super.service(req,res);
        System.out.println(System.currentTimeMillis() +"ThreadingTest 
service ready...  "  + Thread.currentThread().toString());
    }
}




Mime
View raw message