[concurrency-interest] Is this a pattern or an anti-pattern for check-and-act?

Nader Aeinehchi nader at aeinehchi.com
Mon Feb 29 14:17:58 EST 2016


Hello

I saw this pattern on an open source project, and wonder if it is thread
safe?  If so, would it scale?

    private final static Object lock = new Object();

    private static Foo foo;

    public static Foo getInstance(){

        if(foo == null){
            synchronized (lock){
                if(foo == null){
                    foo = new Foo();
                }
            }
        }

        return foo;
    }

In advance, thank you very much

Nader
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20160229/eb6b1537/attachment.html>


More information about the Concurrency-interest mailing list