Select 1 correct option.
1. The container synchronizes access to all variables.
2. The container synchronizes access to session attributes.
3. Only one instance of the
servlet is created.
4. One instance of the servlet per request is created.
5. For simultaneous requests, the container may create more than one instance of the servlet.
You answered WRONG. Correct options are highlighted.
The correct answer given is 5.
But according to me the correct answer is 4. Always one instance of the servlet is created and there can be number of requests to the one instance. But as in our case the servlet is implementing the SingleThreadModel. So only one is created per one instance. As the instance will always remain one for particular servlet in one JVM as always the case is.
Detailed Explanation
When a Servlet implements SingleThreadModel interface (This interface it has no methods), the servlet container makes sure that at a time only one
thread is executing it's methods. If there are multiple simultaneous requests to the same servlet then it may create multiple instances of that servlet. So multiple thread can execute the methods but on different objects. So instance members are virtually thread safe.
This question is from Enthuware.
Please do advise.