SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Originally posted by Ulf Dittmer:
Only one instance is created. I'm surprised that this isn't covered by the SCWCD exam, which -judging by your signature- you have taken.
In the case where a servlet was deployed as part of an application marked in the deployment descriptor as distributable, a container may have only one instance per servlet declaration per virtual machine (VM).
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Originally posted by Amol Nayak:
Is your servlet implementing SingleThreadModel?
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Originally posted by Amit Kumargupta:
If you implement SingleThreadModel interface the server will create multiple instances of servlet.
If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.
Originally posted by David O'Meara:
(bold added by Dave)
Neither of these mention a new instance for each request, although it is a less efficient version of the second option.
[ August 03, 2007: Message edited by: David O'Meara ]
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Originally posted by David O'Meara:
It is one Servlet instance per servlet mapping, since a Servlet class is able to be mapped several times in web.xml
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Originally posted by Chengwei Lee:
I've a servlet that made use of its init method to read a config file and set the values into the servletcontext. Whenever a new HTTP request comes in, will the container creates just 1 instance of the servlets, or many instances could be created?
If 1..* instances of the servlet could be created, does it means that the init method will be called each time an instance is created?
Originally posted by Prem Kashyap:
If you are implementing SingleThreadModel, then obviously, for superior performance you'd want the servlet container to create multiple instances of a SingleThreadModel type servlet should there be many requests received in quick succession. Whether or not a servlet container does that depends completely on the implementation. So it is not guaranteed that if you implement SingleThreadModel, the container will create multiple instances for that servlet.
Regards
Prem Kashyap
SCJP 1.4 : 88%
Originally posted by Santhosh Reddy:
Hello Mr.Lee,,
First thing to note is ,only one instance of servlet will serve all the request's ,secondly multiple instances are created of a servlet when you implement single thread model,Third thing is init method is called only once for every instance of a servlet,
Originally posted by Chengwei Lee:
I was reading the specifications and found the use of the word may, hence the query. Wouldn't this means its up to the servlet container?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |