wrap the call to the logfile in a (new) servlet method which must be
synchronized:

private synchronized void threadSafeLog(String text)
{
        unsafeLog(text);  //calls your previous unsafe logging method
} 

in general every servlet request is executed in a separate thread,
all of which share the data fields of the servlet.
(even if they are not static!)

regards
matthias


-----Urspr�ngliche Nachricht-----
Von: Wes Settle [mailto:[EMAIL PROTECTED]]
Gesendet am: Montag, 23. Oktober 2000 15:13
An: '[EMAIL PROTECTED]'
Betreff: Servlet Variables

I hope this question is not too basic.  I am working with a Java Servlet in
Jakarta Tomcat and seem to be having difficulty with the way that the
servlet is handling multiple requests.  It appears that the servlet's
variables are sharing values and not holding explicit values for each
request.  For example, logging is done by the servlet per machine name
making the request (getHostName()).  If multiple requests are made to the
servlet, the log files are all crossed.  Is there something we are
overlooking in getting the servlet to thread properly?  The servlet extends
HttpServlet.
 
Thanks in advance for any help
 
TWS

Reply via email to