aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes static class variables in SingleThreaded model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "static class variables in SingleThreaded model" Watch "static class variables in SingleThreaded model" New topic
Author

static class variables in SingleThreaded model

Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
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.


Aruna A. Raghavan<br />SCJP, SCJD, SCWCD
shweta mathur
Ranch Hand

Joined: Sep 23, 2002
Posts: 109
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 ]

--Shweta<br />SCJP 1.4 <br />SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static class variables in SingleThreaded model