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

Yes and No. Your singleton_pattern_class will have only one instance in a
*JVM* by placing the required class on the classpath. This happens due to
the delegation model of classloading in Java 2. Every customized (& well
behaved) classloader delegates to the system classloader first, before
attempting to load a class on its own. If you place the class on the class
path, then it is the system classloader which loads it and hence you will
get the same class across different contexts ( only in the same JVM).
If the contexts are distributed across different JVMs then this will not
work. But it depends upon the container also. Although the classloaders in
containers are not supposed to break the delegation model (nothing about
this in the specs), if they break it then also you will not get the desired
results.

But be forewarned that the automatic reloading of classes may not happen for
classes which are on the system classpath. For new classes to take effect
you may need to restart the container.


>
> Bo
> Oct.20, 2000

regds,
Gokul


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