wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes SingleThreadModel Vs Concurrency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "SingleThreadModel Vs Concurrency" Watch "SingleThreadModel Vs Concurrency" New topic
Author

SingleThreadModel Vs Concurrency

gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
We know that SingleThreadModel is used for protecting instance variables. Does't it also affect the concurrency of service() method in servlet?


SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41188
    
  45
Yes. It ensures that the service() method of any particular servlet instance will not be called concurrently by more than a single thread. In other words, there is no concurrency for servlet instances.


Ping & DNS - my free Android networking tools app
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
Just to add here that there may still be multiple instances of the servlet after implementing the SingleThreadModel interface.


SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
Samantha Halpagoda
Greenhorn

Joined: Mar 04, 2007
Posts: 3
Originally posted by Sandeep Bhandari:
Just to add here that there may still be multiple instances of the servlet after implementing the SingleThreadModel interface.


How could that happen? but in HFSJ it says there is only one instance of a servelt at anytime.. and that instance will be used in different threads, so if we have single thread model, is it possible to create/generate multiple instance of same servelt?
could you please explain this further?


SCJP: 1.4
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
Originally posted by Samantha Halpagoda:


How could that happen? but in HFSJ it says there is only one instance of a servelt at anytime.. and that instance will be used in different threads, so if we have single thread model, is it possible to create/generate multiple instance of same servelt?
could you please explain this further?


Here's what SUN says:

In the case of a servlet that implements the SingleThreadModel interface, the servlet
container may instantiate multiple instances of that servlet so that it can handle a heavy
request load while still serializing requests to a single instance.


and a word of caution about assuming that everything is being single instantiated is also given by SUN in the words:

The use of the SingleThreadModel interface guarantees that one thread at a time will
execute through a given servlet instance�s service method. It is important to note that this
guarantee only applies to servlet instance. Objects that can be accessible to more than one
servlet instance at a time, such as instances of HttpSession, may be available to multiple
servlets, including those that implement SingleThreadModel, at any particular time.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41188
    
  45
Note that it's also possible to have multiple instances of the same servlet class if they are configured under different names. This has nothing to do with STM/non-STM, though.
[ August 06, 2008: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SingleThreadModel Vs Concurrency
 
Similar Threads
Threading issues in servlet
SingleThreadModel
Single Thread Model
about threading in servlet.
Servelet instances created in web.xml