Java Servlets threading model Java Servlets threading model multithreading multithreading

Java Servlets threading model


If requests were handled serially by servlets, then web applications would be very slow. It's actually the case that servlets need to be thread-safe, because a single instance of a servlet can be responsible for handling multiple requests simultaneously.

Usually a web application container will maintain a thread pool for handling requests, with incoming requests being assigned to threads on an on-demand basis.


Historically you had two models, depending on your Servlet. If the Servlet implemented SingleThreadModel, then the requests where queued. Otherwise, and this is the only model now, a Servlet must be able to serve multiple requests at the same time. So there is no queueing in that model, unless the container has some rate-limiting functionnality.


yes,there is a interface single thread model .it is a marker interface.it makes this object of servlet synchronized i.e at a time only one thread serve the object.but it create the problems like response delay.for solution they create pool of objects but again pool also has limited size.so it is better to use synchronized block