This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mock ques , confusion.. SingleThreadModel" Watch "Mock ques , confusion.. SingleThreadModel" New topic
Author

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.

Ani


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)


SCJP 5, SCWCD 5, SCBCD 5
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
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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