Per the specs "boolean", even though it is a primitive data type, like double,
is not - atomic - in regards to multithreading
TKV Tyler VanGorder wrote:
> Hi Todd,
>
> Only one instance of the servlet will be created and it will service
> multiple client requests. So if client 'A' changes the variable to true,
> then Client 'B' will see that. Also note, that since it is a boolean value
> you do not need to synchronize your variable because the assignment of the
> boolean is atomic. If you
> were using something like a hash map or other collection, you would need to
> synchronize around access to that instance variable because multiple threads
> of execution could be accessing it concurrently.
>
> If you want the variable to be on a "per-user" basis you will need to store
> that variable in the Session object for each user.
>
> Tyler Van Gorder
> [EMAIL PROTECTED]
>
> > -----Original Message-----
> > From: Todd Mytkowicz [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, July 06, 2000 1:08 PM
> > To: [EMAIL PROTECTED]
> > Subject: Non static global variables
> >
> >
> > Hello all,
> >
> > In my servlet, I create an instance variable as such...
> >
> > private boolean temp = false;
> >
> > ...
> >
> > An instance of this servlet is created the first time the
> > servlet is called.
> > My understanding is that this variable is only initialized
> > that first time.
> >
> > Is this temp variable implicitly static? ie, if one user changes the
> > variable, will other servlets see that change?
> >
> > In more general terms, I want this variable to act as a
> > global variable with
> > a seperate value to each request.
> >
> > If user A requests my servlet and changes the temp to true,
> > will subsequent
> > users see a value of true?
> >
> > Thanks for the help.
> >
> > Todd Mytkowicz:
> > [EMAIL PROTECTED]
> > ______________________________________________________________
> > __________
> > Get Your Private, Free E-mail from MSN Hotmail at
> http://www.hotmail.com
>
> ___________________________________________________________________________
> 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