-----Original Message-----
From: Milt Epstein <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Monday, June 21, 1999 3:54 PM
Subject: Re: Global variable


>On Mon, 21 Jun 1999, Arjan Houtman wrote:
>
>> Don't you get a problem here that you try to make a static reference
>> to a non-static variable? 'instance' is non-static... 'getInstance'
>> is static.
>
>Yes, I believe you are correct.  Doing it from memory, figured I'd
>missed something :-).  The correction is to make instance static (it
>will be a compiler error otherwise).  Also, now that I think about it,
>it's probably a good idea to make getInstance synchronized.
>


Definitly a good idea.
Otherwise the first caller will get one instance of your singleton.
And all the following callers can get another.
(If the first and second caller try to get the same singleton in a very,
very short time-frame.)

So you should make everything from checking on the instance until creation
atomic.

Vince M. Treur

___________________________________________________________________________
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