Typical double check
class DoubleCheck { | |
private SomeResource myResource; | |
public SomeResource getResource() { | |
if(myResource != null) { | |
return myResource | |
} | |
synchronized(this) { | |
if(myResource != null) { | |
return myResource | |
} | |
myResource = new SomeResource(); | |
return myResource | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment