Gokul Singh wrote:
>
> > It worked. Now I had 3 web browsers loaded on my machine and added
> > different values to each text box (one per web page). I then executed the
> 3
> > Web Pages at the same time. Well! the results were different! Sometimes
> all
> > pages showed the same result and sometimes 2 would etc... It took me a
> > while to understand what had happened;
>
> It is sometimes really frustating to debug the bugs introduced due to
> multithreading. You had more than one thread executing through your sevlet
> and that is what caused the problem.
Along with the fact that all three browsers were probably sharing the
same session if they were running on the same machine.
> > I believe that you should not declare
> > objects that will have dynamic data outside of the method that is using
> > them.
>
> I don't think this is correct. Member variables are used for storing
> attributes of classes and the attributes of course can be dynamic in nature.
> The problem that you faced was due to fact that multiple threads were
> executing the same method and hence accessing the same variable
> simultaneously and resulting in inconsistent results. The change to local
> variable in the method resulted in each thread having its own copy of the
> variable and hence the problems disappeared.
But if the variables were changed by the request, doesn't that imply
that the variables are not attributes of the servlet class, but rather
attributes of the request session? I would say yes. If there is
information that is potentially different for each request to a servlet,
then that information should not be stored as a servlet member variable.
K Mukhar
___________________________________________________________________________
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