class MyClass { private static volatile Resource resource; public static Resource getInstance() { if(resource == null)
I think, you should use syncronized keyword before getInstance definition.
syncronized
getInstance
For better performance you can use Double-checked locking pattern: