separate the singleton itself and the factory.

in the previous example:

public class ASingletonFactory{
   private static ASingletonImpl instance = new ASingletonImpl();
   public static  AsingletonImpl getInstance(){
      return instance;
  }
}

public class ASingletonImpl{
   ASingletonImpl(){
   }
   ///real code here
}


regards
Leon

On 2/16/07, Jason Pyeron <[EMAIL PROTECTED]> wrote:
So how should one write their singleton?


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Sr. Consultant                    10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information. If you
have received it in error, purge the message from your system and
notify the sender immediately.  Any other use of the email by you
is prohibited.


-----Original Message-----
From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
Sent: Friday, February 16, 2007 11:33
To: Tomcat Users List
Subject: Re: PermGen space

something like this:

public class ASingletonImpl{
   private static ASingletonImpl instance;
   public synchronized AsingletonImpl getInstance(){
      if (instance==null){
         instance = new ASingletonImpl();
      }
      return instance;
   }

   ///real code here
}

The problem is the cyclic dependence between the Class object, the
ASingletonImpl object and the according ClassLoader. This way nothing
can be freed by the gc.

regards
Leon


On 2/16/07, Jiang, Peiyun <[EMAIL PROTECTED]> wrote:
> Just curious, can you elaborate on badly programmed singletons?
>
> Thanks.
>
> Peiyun
>
> -----Original Message-----
> From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
> Sent: February 16, 2007 11:08 AM
> To: Tomcat Users List
> Subject: Re: PermGen space
>
>
> The typical problem here are badly programmed singletons. Do you have any?
>
> regards
> Leon
>
> On 2/16/07, Davide Romanini <[EMAIL PROTECTED]> wrote:
> > I'm too have this problem, it arises because for some reason the Tomcat
> > WebAppClassloader cannot be garbage collected after undeploy. I made a
> > lot of tests and didn't find any solution, also very simple and small
> > webapps, when loaded/unloaded frequently, caused the problem... :-(
> >
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to