You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steffen Späthe <st...@spaethe.net> on 2006/06/06 09:58:17 UTC
multiple, parallel requests
Hello,
first of all I am new at this mailing-list and would be very glad if
subscribers of this list could help me.
As far as I understand the life cycle of a servlet in a
tomcat-servlet-container, one instance of a servlet is created and when
a request comes in, a thread is started with the service-methode.
In my understanding should an other thread been started with the
service-methode, if the first thread is sill running and a new request
comes in. If this isn´t correct, please correct me.
If this is correct, I don´t know what i´m doing wrong... It doesn´t work
for me. Not in a really simple HttpSerlvet and not in an also simple
JSP. To be more specific: my simple JSPs "needs" 5 sec. (just be
sleep(5000) ) to finish. And if I send multiple requests to tomcat, one
request is processed after the other... just like it is processed in a
queue and not parallel. And not - JSP and Servlet are not implementing
SingleThreadingModel.
Has someone an hint for me?
Thank you very much,
steffen from germany
Re: multiple, parallel requests
Posted by Steffen Späthe <st...@spaethe.net>.
> 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());
}
}
Re: multiple, parallel requests
Posted by Leon Rosenberg <ro...@googlemail.com>.
Maybe you should paste your "simple HttpServlet" code ?
regards
Leon
On 6/6/06, Steffen Späthe <st...@spaethe.net> wrote:
> Hello,
>
> first of all I am new at this mailing-list and would be very glad if
> subscribers of this list could help me.
>
> As far as I understand the life cycle of a servlet in a
> tomcat-servlet-container, one instance of a servlet is created and when
> a request comes in, a thread is started with the service-methode.
> In my understanding should an other thread been started with the
> service-methode, if the first thread is sill running and a new request
> comes in. If this isn´t correct, please correct me.
>
> If this is correct, I don´t know what i´m doing wrong... It doesn´t work
> for me. Not in a really simple HttpSerlvet and not in an also simple
> JSP. To be more specific: my simple JSPs "needs" 5 sec. (just be
> sleep(5000) ) to finish. And if I send multiple requests to tomcat, one
> request is processed after the other... just like it is processed in a
> queue and not parallel. And not - JSP and Servlet are not implementing
> SingleThreadingModel.
>
> Has someone an hint for me?
>
> Thank you very much,
>
> steffen from germany
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: multiple, parallel requests
Posted by Steffen Späthe <st...@spaethe.net>.
Hello Antonio Petrelli,
thank you very much. Now my world is right again.
I tried multiple request from one firefox-instance in multiple tabs. And
this doesn´t work - as you described it. Now I retried it with on
firefox and on internet explorer instance. And it worked as expected. I
thought, i tried two different browsers yesterday ... any way .... now
it works :-) :-) :-)
Thank you very much!
Have a nice week,
steffen
> Steffen Späthe ha scritto:
>> In my understanding should an other thread been started with the
>> service-methode, if the first thread is sill running and a new
>> request comes in. If this isn´t correct, please correct me.
>
> Not always. If you are using HTTP 1.1 persistent connections and you
> are trying to make a request from within the same browser (it should
> be the default if you are using modern browsers and the latest Tomcat
> if I am not wrong...), usually the browser will use the same caller
> TCP port. Because there is a 1:1 mapping between the TCP port and the
> service process (or thread), if the port does not change, the
> thread/process will not change too.
> Just to be sure, open a new browser (I suggest to try with a totally
> different one, e.g. use Firefox and IE) and retry the same experiment.
> HTH
> Antonio
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: multiple, parallel requests
Posted by Antonio Petrelli <br...@tariffenet.it>.
Steffen Späthe ha scritto:
> In my understanding should an other thread been started with the
> service-methode, if the first thread is sill running and a new request
> comes in. If this isn´t correct, please correct me.
Not always. If you are using HTTP 1.1 persistent connections and you are
trying to make a request from within the same browser (it should be the
default if you are using modern browsers and the latest Tomcat if I am
not wrong...), usually the browser will use the same caller TCP port.
Because there is a 1:1 mapping between the TCP port and the service
process (or thread), if the port does not change, the thread/process
will not change too.
Just to be sure, open a new browser (I suggest to try with a totally
different one, e.g. use Firefox and IE) and retry the same experiment.
HTH
Antonio
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org