How to make servlet thread safe?

Answer Posted / shakir khan

There are situations where we want to protect your servlet
member variables from being modified by different
clients.In this case you can have your servlet by
implementing the marker interface SigleThreadModel.

Everytime a client makes request to a servlet by
implementing this interface,servlet engine will create a
new instance of servlet.

For performance reason,servlet engine can also maintain a
instance pool,handing out instances as they are needed.Or
it could also serialize client request executing one after
another.

Is This Answer Correct ?    49 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How are filters?

595


Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?

784


What is new in ServletRequest interface ? (Servlet 2.4)

585


What are different methods of session management in servlets?

785


Differentiate between get and post?

690






Why is a constructor needed in a servlet even if we use the init method?

614


What is load-on-startup in servlet?

594


What are the different ways we can maintain state between requests?

584


Explain jsessionid?

626


What are the jobs performed by servlets?

593


What is the procedure of invoking different servlet in a different application?

571


How do cookies work in servlets?

587


What is httpservlet and how it is different from genericservlet?

617


I Have A Plan to develop a Project in Struts,I want the template of struts project with Hibernate.Canany body provide me the required information?

2244


Why doesn’t a servlet include main()? How does it work?

643