Please read the following fascinating (and intense) discussion on the Singleton
at:
http://www.javaspecialists.co.za/archive/Issue052.html,
and
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html,
to understand why synchronizing creation of the Singleton doesnt always work.
Regards,
Murali Krishna Devarakonda
--------------------------
--- Hugo Pragt <hcgpragt@(protected):
> > maybe even better stil:
> >
> > public class MySingleton {
> > /*
> > * The only instance of the editor - a Singleton
> > */
> > private static final MySingleton instance= new MySingleton();
> >
> > add the final keyword for java optimalisation. You even get a warning when
> > you try to create a second singleton.
> >
> > Hugo
> >
> >
> >
> > ----- Original Message -----
> > From: "Erik Beijnoff" <erik@(protected)>
> > To: <JSP-INTEREST@(protected)>
> > Sent: Wednesday, September 17, 2003 8:33 AM
> > Subject: Re: Singleton Object.
> >
> >
> > > >How do I create singleton object in Java? Can you give some examples on
> > > that.
> > >
> > > It is quite simple. This is a standard singleton pattern.
> > >
> > > --------------------------------------------------------------
> > > public class MySingleton {
> > > /*
> > > * The only instance of the editor - a Singleton
> > > */
> > > private static MySingleton instance= new MySingleton();
> > >
> > > /*
> > > * Constructor - hidden
> > > */
> > > private MySingleton() {
> > > }
> > >
> > > /*
> > > * Main entrance point to get a hold of the instance
> > > */
> > > public static MySingleton getInstance() {
> > > return instance;
> > > }
> > >
> > > /*
> > > * Method to do work
> > > */
> > > public void doSomething() {
> > > }
> > > }
> > > ---------------------------------------------------------------
> > > Erik Beijnoff
> > > Addsystems
> > >
> > > erik@(protected)
> > > erik@(protected)
Regards,
Murali Krishna Devarakonda
mailto:Murali@(protected)
http://www.EJBObject.com
===========================================================================
To unsubscribe: mailto listserv@(protected)".
For digest: mailto listserv@(protected)".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com