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.
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)
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