• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STM and instances of servlets - Whizlabs Question

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit, If we implements STM, then there will be multiple instances of a servlet.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, Again confusions..
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic