Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SingleThreadModel in REAL exam - (is it still as a valid option)

 
Jim So
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I read the following about SingleThreadModel from HF2 book.

Got three questions. Related to what the EXAM says is the correct answer. Not the technical answer - but the answer that the EXAM will select as correct.

Thanks in advance for any help you can provide me.

--------------------
Question ONE:

If you implement SingleThreadModel and use the Queuing strategy - then instance variables are safe.
But if you implement SingleThreadModel and use the Pooling strategy - then you can have multiple threads running a seperate instance of the same servlet.
This will mean that if you use a pooling strategy - the instance variables are not thread safe anymore.

So if the exam asks. "Are instance variables thread safe when using the SingleThreadModel."

Should i answer Yes or No? Because it sort of depends on the strategy you use.
It seems the mock exams on JavaRanch select, Yes as the correct answer, because the Queuing strategy does protect the instance variables. But is this the correct answer in the EXAM?


------------------

Question TWO:

What is an example of implementing thread safety in servlets?

A. implement SimpleThreadModel
B. Syncronise the service method
C. Apply a syncronise block around all of the code that manipulates content attributes in the whole application
D. you cant

From reading the book, i assume these would be considered correct in the EXAM:

A. - because it does add thread safety to instance varibales
C. - because this does protect context attributes, if every setAttribute is in a syncronise block in every servlet in the whole app.

Would this considered correct if questions are asked of it in the real EXAM?

Or would i only select "implement SimpleThreadModel" as a valid answer to a question that specificaly states "what is a method of implementing thread safety for instance varibales"?

-------------------

Question THREE:

Are all of these statemetns considered correct, in the real EXAM?

1: If your servlet is Implementing the SingleThreadModel interface.
then Request,Response,Local variables and Instance variables are Threadsafe.

2: If your servlet is NOT Implementing the SingleThreadModel interface..
then Request,Response and Local variables are Threadsafe.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementing the SingleThreadModel does not put an end to end to the synchronization problems, so you can figure out what are answers to your questions. More info here .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you cannot see from Amit's link is that javax.servlet.SingleThreadModel is deprecated Check the 1.4 API instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic