Contact:   Tel: 2726  -  New Media Systems, 1st Floor South, Queens Walk


This one looks to me more like a thread-safe issue, instead of exception
handling. Each request from a client (usually) starts a new thread on the server
in which your servlet runs. If your object is defined outside of the method, it
is shared by all the three threads. Depending on whether it is a read-only or
mutable object, you may get different results for different clients. Moving the
object into the method is one way of solving the problem, if you really have no
need to shared this object among the threads. Otherwise, you need to use lock or
synchronization.


Cheers,

Charles





Marc Krisjanous <[EMAIL PROTECTED]> on 10/12/2000 09:14:57 AM

To:        [EMAIL PROTECTED]
cc:         (bcc: Charles Chen/YellowPages)
From:      Marc Krisjanous <[EMAIL PROTECTED]>, 12 October 2000, 9:14
           a.m.

A question about the fundamentals!


Hi all,

once again thank you for your comments about exception handling.  I have now
revised by strategy.

One thing I would like to share with you is:

I had a simple servlet that accepts a parameter from a requesting page, it
then adds the parameter to a Result Bean, the bean is then added to the
session object.  A JSP page was then called.  The JSP page then displayed
the results by accessing the Result bean and extracting the parameter value.
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; I add declared by Result bean at the
class level - outside of a method.  I believe that you should not declare
objects that will have dynamic data outside of the method that is using
them.   I removed the declaration from the class level and declared the
Result Bean in the doGet method where it is used.  Now I can have as many
web browser executing at the same time and all displaying the correct
information.

Am I correct in my assumptions - it seems very fundamental.

Best Regards


Marc

___________________________________________________________________________
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

Reply via email to