Java Mailing List Archive

http://www.junlu.com/

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

Fw: Singleton Object.

Hugo Pragt

2003-09-17

Replies:

> 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)
> >
> >
>
===========================================================================
> > To unsubscribe: mailto listserv@(protected)
> JSP-INTEREST".
> > For digest: mailto listserv@(protected)
> DIGEST".
> >
> > 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
> >
>
>
===========================================================================
> To unsubscribe: mailto listserv@(protected)
JSP-INTEREST".
> For digest: mailto listserv@(protected)
DIGEST".
>
> 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
>

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