java - Servlet seems to handle multiple concurrent browser requests synchronously -
as far know java servlets handling multiple requests concurrently , i've searched through stackoverflow google, , confirmed thought. quite confused right now, wrote simple servlets seem show blocking behaviour.
so have simple servlet:
public class myservlet extends httpservlet { private static final long serialversionuid = 2628320200587071622l; private static final logger logger = logger.getlogger(myservlet.class); @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { logger.info("[doget] test before"); try { thread.sleep(60000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } logger.info("[doget] test after"); resp.setcontenttype("text/plain"); resp.getwriter().write("ok"); } }
then have 2 browser windows, opened @ ~same time hit servlet. , result first request blocking 2nd one. log shows:
10:49:05,088 [http-8383-processor14] info myservlet - [doget] test before 10:50:05,096 [http-8383-processor14] info myservlet - [doget] test after 10:50:05,106 [http-8383-processor22] info myservlet - [doget] test before 10:51:05,112 [http-8383-processor22] info myservlet - [doget] test after
i feel missing ... servlets supposed able handle concurrent request, doesnt seem doing it. did same above on service method instead of doget , same thing.
any pointers?
thanks
your browser apparently using same http connection in different windows. servlet container uses single thread per http connection, not per http request. should run 2 physically different webbrowsers test properly. e.g. 1 firefox , 1 chrome.
Comments
Post a Comment