This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Mock ques , confusion.. SingleThreadModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mock ques , confusion.. SingleThreadModel" Watch "Mock ques , confusion.. SingleThreadModel" New topic

Mock ques , confusion.. SingleThreadModel

ani jadhao
Ranch Hand

Joined: Dec 23, 2008
Posts: 62
The question from mock of Berts is

How to deal with servlets and thread safety?
A Extend ThreadSafeServlet
B Log all messages
C implenent SingleThreadModel
D User exclusively local var and for instance var , synchronize them.

Now I seem two currect answers C and D .But in mock correct answer has been given only D.
So my question is even though interface SingleThreadModel has been deprecated , will it be considered as a valid answer in exam , or it should not count in correct answer options.

Looking for reply.


SCJP 1.4 : 91%
SCWCD 5: 96%
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

singleThreadModel doesn't answer all thread safety problems.
in fact, some implementation creates more problem than they
solve and this is exactly why this interface has been deprecated.

in brief, this interface protect instance variable from concurrent access,
but shared attribute are still not thread safe (context and session attribute,
for example, can be accessed from different servlets. in this case YOU should
take care of thread safety, by locking on the context or the session)

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
in addition suppose that you invoke another thread from your doXXX method and you pass it the HttpServletRequest object, by doing this your HttpServletRequest object will not be thread safe anymore. in addition to this case there is no way that the SingleThreadModel makes your attributes in the HttpSession and the ServletContext thread safe which makes option C incorrect

Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

I thought about session and context attributes as well, but answer D doesn't address these either - it only mentions synchronizing the instance vars.

How To Ask Questions How To Answer Questions
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

then maybe it's because this class is deprecated so this isn't how to "deal with servlets and thread safety"....
Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

Well that would explain why C is false. You indeed shouldn't use SingleThreadModel, so it's never a (good) solution.
subject: Mock ques , confusion.. SingleThreadModel
Similar Threads
SingleThreadModel in REAL exam - (is it still as a valid option)
Garbage collect from Exam
Question about JSTL (c:remove)
Thread Safe Servlet