Actually, what is created in your example is a local reference to a shared object. The real question is can one of my objects be modified by some external force. That external force could be many things one of which is another thread of execution in this program. If you reference objects that have external representation (database, file, shared memory, network, etc) they all can be changed by external forces. Thus care must be taken to either: 1) Handle all possible changed in the code that references the objects. 2) Handle all possible changes in the objects themselves. 3) Some middle ground, where that middle ground is well documented and understood by both the object implementor and the object user. The debate that constantly rages is which of the three mechanisms above is "best". And the answer is.....depends upon your needs! Enjoy, Brian -----Original Message----- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 07, 1999 12:37 AM To: [EMAIL PROTECTED] Subject: Re: Can some explain/confirm 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 ___________________________________________________________________________ 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
