InterviewSolution
| 1. |
Explain the Single-Thread Model in servlets. |
|
Answer» It is STANDARD to have a single servlet instance for each registered name of the servlet. However, instead of this, it is also possible for a servlet to choose to have a pool of instances created for each of its names that all share the task of handling requests. These servlets indicate this action by implementing the javax.servlet.SingleThreadModel interface. According to the Servlet API documentation, a SERVER LOADING the SingleThreadModel servlet should guarantee, “that no two threads will execute CONCURRENTLY the service method of that servlet.” Each thread uses a free servlet instance from the pool in order to achieve this. Therefore, any servlet using the SingleThreadModel isn’t needed to synchronize USAGE to its instance variables and is considered thread-safe. |
|