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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SingleThreadModel" Watch "SingleThreadModel" New topic
Author

SingleThreadModel

Veri
Greenhorn

Joined: Jul 01, 2002
Posts: 1
I have a Servlet that implements SingleThreadModel interface, and contain a instance variable (for example int count). The doGet(...) method increment and display this variable.The servlet name in the web.xml is: servlet1. For a SingleThreadModel servlet there is a pool of instances for each call with servlet1. Is the value of count variable consistent between servlet1 calls? Why?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Veri,
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Not necessarily. If the servlet engine spawns multiple instances of your servlet, each one will initialize its own instance variable, starting at zero.
To make it consistent, you need to make your variable static and use a synchronized get method.
If you only ever have one user, you might survive.
:roll:


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SingleThreadModel
 
Similar Threads
SingleThreadModel
Servlet instances and its init method
problem of thread safe
Does SingleThreadModel ensure thread-safety?
HTTP 404 error problem