What is SingleThreadModel?

Normally in servlet the system makes a single instance of the servlet and then creates a new thread for each user request with multiple concurrent threads running, if a new request comes while a previous request is still executing then multiple threads may access the data simultaneously which may result dirty read in some cases. It can be prevented by implementing SingleThreadModel interface.
Public class myServlet extends HttpServlet implements SingleThreadModel{}
This interface has no methods, it is only for, to tell the container that there is never more than one request thread accessing a single instance of the servlet. It does so by queuing all the requests and passing one at a time to the servlet. By this performance goes down because many times the server remains idle, for example when a request is executing and waiting for an I/O then the server has nothing to do.It is designed to protect the instance variables. It can not help class variables.
Now the SingleThreadModel is deprecated from servlet API.

No comments:

Post a Comment