Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is MyServlet Thread Safe

 
Krupa Eng
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If MyServlet implements singleThreadModel, I read some where that I Can say that MyServlet is Thread safe, But what happens when the multiple instances are created by the servlet container. Shouldn't the methods of MyServlet be synchronized to make sure that MyServlet is Thread Safe.
Thanks in Advance
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krupa,
Implementing SingleModeThread does not guarantee the servlet to be thread-safe, as the container may create multiple instances of the servlet class to process multiple requests.
 
Rakesh Jhamb
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementing SingleThreadModel interface only guarantees that no two threads will execute service() method on the same instance. Everything else like static variables(not thread safe), session scope, context scope etc. is developer's pain and he has to take care of it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic