ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Servlets
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1720)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (43)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (195)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (145)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
What is Single Threaded Model in Servlets? Explain this 
with an example?
 Question Submitted By :: Nimitha
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 1
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 ?    50 Yes 3 No
Niranjanravi
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 2
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 ?    27 Yes 7 No
Devarathnam
 
 
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 3
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 4 No
Sateesh.b
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 4
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
Balu
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 5
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 ?    34 Yes 3 No
Anjali Nema
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 6
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 2 No
Nishant
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 7
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
Yuvraj Singh
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 8
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 4 No
Rajkumar
 
  Re: What is Single Threaded Model in Servlets? Explain this with an example?
Answer
# 9
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 ?    12 Yes 1 No
Rajesh R
 

 
 
 
Other Servlets Interview Questions
 
  Question Asked @ Answers
 
which method in doGet or doPost is use to send binary date to server HCL 2
What is connection pooling? Wipro 4
What is the default HttpRequest method?   6
Can threads be used in Servelet?   3
Difference Between Web Server and Application server ?? PWC 3
What compiler do not do if we create our own constructor? HCL 5
what is OOAS iGate 2
Explain life cycle of a Servlet?   2
Is there any differance b/w getting servlet context from servlet config and session? if yes then what is that?   7
What are cookies and how will you use them?   2
How an Image can be loaded in a Servlet ?   1
What is the role of the webserver?   4
 
For more Servlets Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright © 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com