aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes STM and instances of servlets - Whizlabs Question 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 "STM and instances of servlets - Whizlabs Question" Watch "STM and instances of servlets - Whizlabs Question" New topic
Author

STM and instances of servlets - Whizlabs Question

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066


Which of the following statements are true? Choose all apply.

1) Multiple instances created for a servlet implementing SingleThreadModel.
2) No more than one instance created for a servlet which is implementing STM.
3) Even static variable is Thread Safe for a servlet implementing STM.
4) If no threading model is implemented, the default a servlet is executed in multi-threaded model


What is the answer? I know, 4 is correct. What about 1 & 2? I thought 2 is correct, but their answer is 1 & 4. Is correct? Please Explain.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Instances of a servlet which implements SingleThreadModel will serve only one requeest at a time. So to allow multiple requests to be served by the servlet, the server creates multiple instances of a SingleThreadModel servlet. This is why option 1 is correct...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks Ankit, If we implements STM, then there will be multiple instances of a servlet.
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

euch I think this conclusion is wrong.
the way STM is implemented depends on your container
It may create multiple instances of the servlet or it may queue the
requests to pass them one at the time to 1 servlet it depends...

I would chose only answer 4 to be correct.


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Oh, Again confusions..
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

sorry ;)

I'm just pretty sure that only answer 4 is correct and your exam is wrong.

I shall quote Head First Servlets and Jsp page 201 if I may...

But how does the web container guarantee a
servlet gets only one request at a time?
The web container vendor has a choice. The container
can maintain a single servlet, but queue every request and
process one request completely before allowing the next
request to proceed. Or the container can create a pool of servlet instances and process each request concurrently,
one per servlet instance.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Exactly, Well said Mark, On that book,

STM interface ensures that servlet handles only one request at a time. You are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.


So, the answer is only 4. And the mock exam is wrong in answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STM and instances of servlets - Whizlabs Question