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


Please Help Members By Posting Answers For Below Questions

How we can create war file in servlet?

672


Difference between java beans & servlets?

597


What is the GenericServlet class?

614


Explain how does JSP handle run-time exceptions?

590


What is the use of welcome-file-list?

580






Why servlet is mostly used?

753


What do you mean by default initialization in java servlet?

613


How can an existing session be invalidated?

673


What do you mean by web applications?

641


How is an application exception handling is done using a servlet?

547


What is difference between cookies and httpsession?

554


How do servlets work?

548


What do you mean by httpservlet?

568


If my browser does not support cookie, and my server sends a cookie instance what will happen?

659


What do you mean by session tracking and also explain its techniques?

506