Dunith Dhanushka Dunith Dhanushka - 26 days ago 4
Java Question

Java Servlets threading model

I was wondering if anybody could explains me the threading model of Java Servlets?
As I understood about that, there is only one instance of a servlet can be existed in the servlet container and if muliple threads happens to be waiting for that servlet, there requests are serialized in some manner.
I don't know how that serialization process happens...

Can anybody explain it?

Answer

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.