• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock ques , confusion.. SingleThreadModel

 
ani jadhao
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jonathan Elkharrat
Ranch Hand
Posts: 170
Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought about session and context attributes as well, but answer D doesn't address these either - it only mentions synchronizing the instance vars.
 
Jonathan Elkharrat
Ranch Hand
Posts: 170
Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then maybe it's because this class is deprecated so this isn't how to "deal with servlets and thread safety"....
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic