Unfortunately JCS requires predictable initialization orders in a lot of
these cases (things must be configured before getCacheManager is called
for example). I don't know how safe it is to rely on the classloader for
this case. It seems like we have to incur the cost of synchronizing the
'ensureCacheManager' method if we want to be truly safe.

Thanks,
James

On Wed, 2002-03-13 at 16:44, Jon Scott Stevens wrote:
> on 3/13/02 4:55 AM, "Pete Kazmier" <[EMAIL PROTECTED]> wrote:
> 
> >  private static Foo foo = null;
> >  
> >  public static Foo getFoo() {
> >      if (foo == null) {
> >          synchronized (Foo.class) {
> >              if (foo == null)
> >                  foo = new Foo();
> >          }
> >      }
> >      return foo;
> >  }
> 
> One way to deal with this is to write it like this:
> 
> public class FooManager
> {
>     private static Foo foo = null;
> 
>     static
>     {
>         foo = new Foo();
>     }
> 
>     public static Foo getFoo()
>     {
>         return foo;
>     }
> }
> 
> That way, no sync needs to happen anyway.
> 
> -jon
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to