wood burning stoves 2.0*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Tony Alicea

Joined: Jan 30, 2000
Posts: 3222
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 http://java.sun.com/j2ee/j2sdkee/techdocs/api/javax/servlet/SingleThreadModel.html such model.
An I agree w/Phil, BTW.

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Consider Paul's rocket mass heater.
subject: SingleThreadModel
Similar Threads
Q about servlet instances in containers.
Question ID :995549757220
Single ThreadModel
Servlet instances and its init method