Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static class variables in SingleThreaded model

 
Aruna Raghavan
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Manning book says -
"In fact, class variables are unsafe even for the Single Threaded model, because multiple threads may access the same class variable from different servlet instances."
So, Single thread model servlets are not really thread safe, are they?
Thanks,
Aruna.
 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the SingleThreadModel servlets are not always thread safe. Implementing this interface only guarantees that in case of multiple requests, Instead of executing the service() method in more than one thread, the container will create multiple instances of the servlet class.
Class variables are common among different instances, therefore multiple threads may access the same class variable from different servlet instances which makes them thread unsafe even though the servlet implements SingleThreadModel.
[ February 01, 2003: Message edited by: shweta mathur ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic