• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SingleThreadModel

 
Veri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic