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.
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?
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"?
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.