Help me out here.
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/service-threads.h
tml
public ShutdownExample extends HttpServlet {
private int serviceCounter = 0;
private Object lock = new Object();
...
//Access methods for serviceCounter
protected void enteringServiceMethod() {
synchronized(lock) {
serviceCounter++;
}
}
protected void leavingServiceMethod() {
synchronized(lock) {
serviceCounter--;
if (serviceCounter == 0 && isShuttingDown())
notifyAll();
}
}
protected int numServices() {
synchronized(lock) {
return serviceCounter;
}
}
}
"Because multiple threads will be accessing the field, and the destroy
method will wait for the field to reach zero, field accesses should be
synchronized. "
This makes it sound like Object instance variables are in danger of multiple
threads accessing them. Do multiple threads travel through the servlet? I
know you said one servlet per HttpSession is created, but I didn't know if
potentially multiple threads can travel through the servlet due to multiple
concurrent requests in a session.
I noticed in my research on servlets that they always talk about using
HttpSessions to save state information. I never hear of anyone using object
instance variables. Do you think the phrase "don't use Object instance
variables to save state information" is implied or am I overly concerned
here?
I wanted to save state information as to whether the client is in one mode
or another mode. I thought I could do this because there should be 1
servlet per browser user (HttpSession)
To sum up, the questions were:
Do multiple threads travel through the servlet?
Do you think the phrase "don't use Object instance variables to save state
information" is implied or am I overly concerned here? (Can a person safely
use Object Instance variables in Servlets just like typical standard Java
objects?)
This all started when I noticed that Object Instance variables (non static
variables) were not being used anywhere in Servlets.
Thanks,
Michael Finney
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html