File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes SingleThreadModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "SingleThreadModel" Watch "SingleThreadModel" New topic


Chris Salivar
Ranch Hand

Joined: May 25, 2001
Posts: 34

If a servlet implements the SingleThreadModel interface then will the instance variable of the servlet be thread-safe?
- Chris
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Yes, but it's almost always a poor design to do this. Why do you need instance variables to be persistent? An HTTP session is a much cleaner way to do this. SingleThreadModel does not scale well.
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
Yes. That's what implementing the model entails.
I am leaving out (since you didn't ask) the details of how a Servlet engine would implement such model.
An I agree w/Phil, BTW.

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
I agree. Here's the link:
subject: SingleThreadModel
It's not a secret anymore!