Hello Tyler,
I am glad you brought up the Collections point. I am using a Hashtable as
an instance variable in my servlet. That Hashtable is itself synchronized.
(Implemented inside the Hashtable class). I am guessing that because of the
Hashtable being synchronized I should not have to worry about synchronizing
access to it. Could you back me up?
I am not using the session object because we are using JSDK2.0 and that
object did not exist with that release. ( Upgrade is in the near future...I
hope :) )
Any other suggestions out there for using a non static global variable???
-Todd
>From: TKV Tyler VanGorder <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: Non static global variables
>Date: Thu, 6 Jul 2000 13:32:23 -0700
>
>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
________________________________________________________________________
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