What is Single Threaded Model in Servlets? Explain this
with an example?
Answer Posted / anjali nema
Typically, a servlet class is instantiated the first time
it is invoked. The same instance will be used over several
client requests, so all members that are declared in that
servlet are shared accross clients. That is what is meant
by multi threaded model, multiple clients that access the
same instance.
There are situations where you want to protect your servlet
member variables from being modified by different clients.
In this case, you can have your servlet implement the
marker interface SingleThreadModel. Every time a client
makes a request to a servlet that implements this
interface, the engine will create a new instance of the
servlet. For performance reasons, the engine can also
maintain a instance pool, handing out instances as they are
needed. Or it could also serialize client requests,
executing a single request.
| Is This Answer Correct ? | 38 Yes | 3 No |
Post New Answer View All Answers
How can an existing session be invalidated?
Which event is fired at the time of session creation and destroy?
Can you call a jsp from the servlet?
Why do we need servlet filter?
What's the architecture of a servlet package?
What are all the protocols supported by httpservlet?
What are the types of servlets? Explain
What is the requirement of servlet config and servlet context implemented and how are they implemented?
Why doesn’t a servlet include main()? How does it work?
Should I override the service() method?
How can you run a servlet program?
What is the difference between Difference between doGet() and doPost()?
Why is a constructor needed in a servlet even if we use the init method?
What is api in servlet?
How can we invoke another servlet in a different application?