more better,

         /*
          * Main entrance point to get a hold of the instance
          */
         public static synchronized MySingleton getInstance() {
                 return instance;
         }

 Append "synchronized" key word.

----- Original Message -----
From: "Erik Beijnoff" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 17, 2003 4:33 PM
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
>
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
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 [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST 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

Reply via email to