• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

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

Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
Posts: 2856
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
Posts: 14691
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Evacuate the building! Here, take this tiny ad with you:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic