Hi,
   I have a similar question. I have a servlet that does some database
updates. Now I am connecting to the database and preparing the statement in
the init method of the servlet. Now I want to know that if different threads
of this servlet execute the service method concurrently, will that create
inconsistent results as my Prepared Statement is declared outside the
service method.
Thanks in Advance,
Raj

----- Original Message -----
From: Bo Xu
To: [EMAIL PROTECTED]
Sent: Thursday, October 12, 2000 7:50 PM
Subject: Re: A question about the fundamentals!


Hi,

> ... 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.  ...


I got the same "result :-) " from my testing, and I just try to add a note,
I am

sorry some of the following have already been explained in several emails,
I just want to explain it more clear :-)


0  for the servlet engine which only make ONE instance for
    "our custom servlet  class" -- normally(I guess) :
    a    -- for "static class variable"
          [a]   all the "static class variable" will be "shared" to all
                 new threads -- and to all "client reauestings" , this is
                 because now we have only one "custom servlet
                class" .
          [b]  So we can not use it as "dynamic data" which is
                 different to every "client requesting".
          [c]   But we can use it to lock our code between those threads.

    b    -- for "not_static class variable"
          [a]    all the "not_static class variable" will be "shared" to all
                  new threads -- and to all "client reauestings" , this is
                  because now we have only one instance.
          [b]   So we can not use it as "dynamic data" which is
                  different to every "client requesting".
          [c]    But we also can use it to lock our code  between those
threads.

    c    -- for "method variable"
          [a]    all the "method variable" will NOT be "shared" to all
                  new threads -- and NOT to all "client reauestings"  I
guess
this is
                  because every new thread will use its own  "copy"
                 for these "method variable"
         [b]   So we can use it as "dynamic data" which is
                  different to every "client requesting".
          [c]    But we can NOT use it to lock our code  between those
threads.


1  for the servlet engine which will make "instance pool"  for
    "our custom servlet  class" , I don't know :-)  But it seems
    that now these instances are "independent:-) ", if So, I
    guess 0-a and 0-c are still right, but 0-b is not right.



Bo
OCT.12, 2000




Marc Krisjanous wrote:

> 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

___________________________________________________________________________
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