-----Original Message-----
From: Nic Ferrier <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, September 07, 1999 5:45 AM
Subject: Re: Thread Safety
>>>> Karl Doane <[EMAIL PROTECTED]> 9/7/99 12:19:03 PM >>>
>>I have read that the dopost and doget method
>>are thread safe since each thread has a copy of its own.
>
>This is not quite true.
>
>There are many threads but only one copy of each servlet.
>
>Each thread does have it's own stack so local variables (created
>within a method) are safe from other threads.
>
>If a method (even doGet() or doPost()) creates class level variables,
>either instance or static, access to those variables must be
>synchronized (because more than one thread at a time might be running
>the method that accesses them).
>
>>My question is, if I create a local variable (a vector)
>>to that method and then pass that variable off to
>>another method which will write it to an output stream,
>> can I safely use that variable in this method??
>
>Yes. You can see from my statement above, the vector is local, so it
>is within the stack of the individual thread.
>
>You can make as many calls you like to diferent methods with
>variables created locally.
>
>As soon as you create or access a variable outside the scope of the
>method however, you will have to synchronize access to it.
>
Do you need to synchronize if you ONLY access data members or static
variables?
___________________________________________________________________________
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