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


I believe someone (Christopher K?)  has already answered this question that
although in practice, this should be the case; in theory (by spec), different
classLoader may create different instance of the static variables of the same
class. As singleton class implementation replies on static variables, meaning,
your singleton class may not be single at all;-(

Why would Java do something like this? I wonder what is the reason behind this
spec.....


Charles





Bo Xu <[EMAIL PROTECTED]> on 10/20/2000 02:50:31 PM

To:        [EMAIL PROTECTED]
cc:         (bcc: Charles Chen/YellowPages)
From:      Bo Xu <[EMAIL PROTECTED]>, 20 October 2000, 2:50 p.m.

Re: Object available to multiple servlets  [Scanned by Yellow Pages PostMaster]


Hi,

I have a question about Servlet + singleton_pattern_class  :-)


Can we be very sure that   -->
in any Servlet engine, our singleton_pattern_class will only have
one instance?   :-)


Thanks in advance!


Bo
Oct.20, 2000




Steven Owens wrote:

> >   Hi, I have a need to write to a file from multiple servlets,
> > possibly all sending requests at the same time. So, I have an object
> > which is created in the init() routine of one of my servlets, as
> > follows:
> > [...]
> >   This is all working, pretty much. But I am confused about how to
> > ensure that the object is initialized before other servlets attempt
> > to use it?
>
>      Go look up the "singleton" pattern.  The basic details are:
>
>      give the pieLog class a private constructor
>
>      give the class an instance variable that holds a reference to an
>           instance of pieLog
>
>      give the pieLog class a static getPieLog() method that:
>
>           1) if the instance variable is null, calls the private
>              constructor
>
>           2) returns the object inside the instance variable,
>
>      It's late, I'm tired, I haven't even looked at source code in a
> month or two, and haven't looked at a singleton in many months, so go
> read up on it.  It's been discussed many, many times.
>
> Steven J. Owens
> [EMAIL PROTECTED]
>
> ___________________________________________________________________________
> 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