What is Single Threaded Model in Servlets? Explain this
with an example?

Answers were Sorted based on User's Feedback



What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / niranjanravi

Single Thread Model ensures that servlet handles only one
request at a time.When YOUR CLASS IMPLEMENTS THIS INTERFACE
WE ARE GUARENTEED THAT no two threads run simultaneously in
service() method.
this is a marker interface which contains no methods on its
own.

Is This Answer Correct ?    53 Yes 3 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / 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

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / devarathnam

Hi... Actually "SingleThreadedModel" is a marker
interface,which doesnot contain any methods.By default
servlet is multithreaded.If u want to make this as single
theaded u can implement this interface in the following
fashion.
public class SingleThreadedTest implements SingleThreadModel
{
//some code
//....
//....
//....
}It is Thread-safety mechanism on a shared resource.

Is This Answer Correct ?    28 Yes 7 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / rajesh r

Hi

The SingleThreadedModel has been deprecated from Servlet
specification due to a performace hit.

Please donot use this in future use Synchronized block if
you really need to protect your Attributes from cuncurrent
access.

Thanks
Rajesh
rajeshr1988@gmail.com

Is This Answer Correct ?    13 Yes 2 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / sateesh.b

SingleThreadModel is a taged interface i.e. an interface
with out methods.
If any servlet is implimenting singlethreadmodel interface
that servlet is said be thread safe i.e. for each request
to that servlet one new object will be created in the server

Is This Answer Correct ?    13 Yes 5 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / nishant

Single thread model is generally not used because it
increases the burden and overhead on the container because
it has to make new instance of the servlet for each and and
every new request.
Sometimes we need to achive the Single thread model in
order to secure our web-application.

Is This Answer Correct ?    11 Yes 3 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / m.rajkumar

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 ?    1 Yes 0 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / rajkumar

In Single Thread model multiple instances of Servlet class
is Created for every request and in MultiThread model thread
instance is created for every request.
Single thread model is used in case code safety.Performance
fo server is degraded when we use single thread as it
creates Servlet instance for every request where server
gives fast response in multi thread model.

Is This Answer Correct ?    5 Yes 5 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / yuvraj singh

SingleThreadModel is a marker interface. It is used to ensure that servlet handle only one request at a time.

Servlets can implement SingleThreadModel interface to inform the container that it should make sure that only one thread is executing the servlet’s service() method at any given moment.

Is This Answer Correct ?    2 Yes 3 No

What is Single Threaded Model in Servlets? Explain this with an example?..

Answer / balu

But see when a servlet implements singleThreadModel, as the
singleThreadModel is marker how come the servlet comes to
know that servlet is threadsafe?...

Is This Answer Correct ?    4 Yes 10 No

Post New Answer

More Servlets Interview Questions

What is the difference between an applet and a servlet?

15 Answers   GCEW, Miracle Solutions,


What is MIME Type?

0 Answers  


What is a parser. What does a parser do with a XML? Why do we need it?

1 Answers  


What is servlet exception?

6 Answers   EDS, Spa IT Solutions,


i am bca student,give me suggest for bright future

18 Answers   BSNL, Future Considerations,






What is difference between ServletResponse sendRedirect() and RequestDispatcher forward() method?

0 Answers  


When a client request is sent to the servlet container, how does the container choose which servlet to invoke?

0 Answers  


What are the types of ServletEngines?

1 Answers  


How many Cookies can a host support?

2 Answers  


Why do you use session tracking in httpservlet?

0 Answers  


What is servlet container. how it works?

0 Answers  


What is servlet instance?

0 Answers  


Categories