Mukul Gandhi wrote:

> 2. Since local variables in class methods come into existence only when the
> method gets called, they will be created fresh for each method call.
>

The local variable comes into existence when the method gets called, but that
does NOT guarantee that the object these variables refer to are thread safe.
For example, if you have the following statement in your doGet() or doPost()
method:

    HttpSession session = request.getSession(true);

you have just created a local variable named "session", but the session object
itself is shared -- and, in particular, the objects that users store there
with session.putValue() need to be designed to deal with a multi-threaded
environment.

The only time you have no worries at all is when:
* You create a new variable (using the "new" operator or an appropriate
factory method of an existing object)
* The new object contains no references to other objects that might be shared.

The principles of programming for a multithreaded environment can be learned
from Computer Science textbooks that discuss the topic, as well as language
tutorials (such as the Java Language Tutorial at
http://java.sun.com/docs/books/tutorial) that illustrate the concepts in
depth.

> --Mukul Gandhi
>

Craig McClanahan

___________________________________________________________________________
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

Reply via email to