How to make servlet thread safe?

Answer Posted / bhaskar padala

The servlet programmer should implement SingleThreadModel interface to ensure that servlet can handle only one request at a time. It is a marker interface, means have no methods.


This interface is currently deprecated since Servlet API 2.4 because it doesn't solves all the thread-safety issues such as static variable and session attributes can be accessed by multiple threads at the same time even if we have implemented the SingleThreadModel interface. So it is recommended to use other means to resolve these thread safety issues such as synchronized block etc.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are Servlets?

609


What is the major difference between context parameter and context attribute?

603


Explain the jar and war files in servlet?

564


Difference between httpservlet and generic servlets?

610


How do you design microservices?

631






Write the code to get the server information in servlet.

587


Which http method is said to be non-idempotent and idempotent?

616


What is java servlet?

616


Explain how to improve Servlet Performance?

604


Write a simple servlet program to print the contents of html.

561


Whether we can get deadlock situation in servlets?

582


How do I support both get and post from the same servlet?

708


How can you create a session in servlet?

604


Why are http servlets used in programming?

556


What exception should be thrown when servlet is not properly initialized?

563