Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

Re: Fw: Singleton Object.

Murali Krishna devarakonda

2003-09-17

Replies:

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 doesn’t 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


©2008 junlu.com - Jax Systems, LLC, U.S.A.