|
Java™ by example!
|
|
|
How does threading work in Servlets?
Every Servlet contains a doGet or doPost method. When we deploy a servlet the init method of the servlet is called. And after it has been deployed on each request of the servlet a separate thread is created to process the doGet/doPost method of the servlet. So all the instance variables of the servlet are not thread safe. We can override this behaviour by implementing SingleThreadedModel in the servlet which tells the servlet container to create a new Servlet instance for each client's request instead of using a single Servlet Instance.
Whether we should implement single threaded model or not depends solely on our design.
Further Information
Author of answer: Khem Chand Sachdeva
Comments
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|