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]>

Reply via email to