• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mock exan question

 
Dave Teare
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:
Which of the following are considered ThreadSafe?
context attributes
class variables
request attributes
local variables

The question asks for 2 answers, but is there not only one correct answer, namely local variables?
Thanks for any insight!
--Dave.
 
Jagdeep Singh
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct answer is "Local variables" & "Request variables". Servlet request object is accessed by only one thread because container creates a new ServletRequest object for each request it receives. Since only one thread service the request at any time, request scope is thread safe and so are variables there in. ( Assuming we are no creating threads in doXXX() methods ).
 
Hafizur Rahman
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Jagdeep Singh.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!