dcsimg
Concurrency problem/question
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Achilleus_Mantzios
Posted On:   Thursday, March 21, 2002 11:52 PM

JSP Page I have found that in tomcat 4.0.1, tomcat 4.0.2 and jetty 3.1.3-1, threads that serve the same servlet for the same URL block until a already running thread finishes, and i wander if this is spec compliant behaviour. Bellow is a simple jsp that demonstrates the problem. (I used jsp and not servlet in the example for due the size of code) If i call from 2 clients something like 1) http://myhost/threadtest.jsp?param1=foo1&param2=foo2 and 2) http://myhost/threadtest.jsp?param2=foo2&param1=foo1 , respectively, then two concurrent threads serve this jsp. How ev   More>>
JSP Page

I have found that in tomcat 4.0.1,
tomcat 4.0.2 and jetty 3.1.3-1,
threads that serve the same servlet
for the same URL block until
a already running thread finishes,
and i wander if this is spec compliant
behaviour.


Bellow is a simple jsp that demonstrates
the problem. (I used jsp and not servlet
in the example for due the size of code)
If i call from 2 clients something
like


1) http://myhost/threadtest.jsp?param1=foo1&param2=foo2
and


2) http://myhost/threadtest.jsp?param2=foo2&param1=foo1

, respectively, then two concurrent threads
serve this jsp.
How ever if call


1) http://myhost/threadtest.jsp?param1=foo1&param2=foo2
and


2) http://myhost/threadtest.jsp?param1=foo1&param2=foo2

, that is identical URLS, then the second thread blocks until the first one finishes.

			
<%@page contentType="text/html" isThreadSafe="true"%>



<%
System.out.println("In the begin damn");
Thread.sleep(5000);
%>





Thanx for any input.    <<Less

Re: Concurrency problem/question

Posted By:   Bozidar_Dangubic  
Posted On:   Friday, March 22, 2002 05:59 AM

how do you know that second thread blocks until first one finishes? you are blocking the thread yourself with the sleep() invocation so both threads are blocked when the request is made. I used your servlet, run it with a 50 threads and all executed within 10000 miliseconds from when they were started.

Re: Concurrency problem/question

Posted By:   Achilleus_Mantzios  
Posted On:   Friday, March 22, 2002 03:23 AM

Just to add some more things.


My servlet


a) Dosnt implement SingleThreadModel


b) Dosnt synchronize over resources


c) Dosnt have service methods synchronized


Also in paragraphs 2.2.1 and 2.3.3.1 of the servlet
2.3 specs it is stated clearly that if none of
conditions a), c) hold then requests should be
served simultinously.


It is strange that after mail bombing
any servlet related list, i still have
no input at all, not even a sign that
somebody has read my message!


Please try with the following servlet.



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

public class ThreadTest extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

protected void processRequest(HttpServletRequest,HttpServletResponse
response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
System.out.println("In the begin damnit");
try {
Thread.sleep(10000);
}
catch (Exception e) {}
}

protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
}
About | Sitemap | Contact