Mukta Josh wrote:I meant the way container implements servlet instance creation. How concurrency will get affected if multiple instances of same servlet are created to process concurrent requests.
Ron McLeod wrote:I believe that a container normally creates only a single instance of the servlet class, and has multiple threads which can concurrently call the instance's service method.
Stephan van Hulst wrote:Hmm I just read part of the spec. Servlet containers must only ever create one instance of a declared servlet, except if the servlet implements SingleThreadModel, as Mukta already pointed out. If a servlet implements SingleThreadModel, its service() method is run by no more than one thread at a time, but the servlet container is free to create multiple instances of the servlet to handle requests concurrently anyway.
Mukta Josh wrote:if my servlet is stateless (which means it doesn't have any instance or class variables
if container creates multiple instances of same servlet for different requests, concurrency is not lost.
But then the mention and recommendation in servlet specification to follow one instance-multiple threads policy, is it just because creating servlet instance is expensive operation or am I missing something here?
Consider Paul's rocket mass heater. |