So in my current project I have code like this:
private static final Object LOCK_OBJECT = new Object();
private static Service getEntryPoint() {
synchronized (LOCK_OBJECT) {
if (entryPoint != null) {
return entryPoint;
}
return new Service();
}
}
My question is: what's the difference between this approach and "classic" singleton aproach: And what is actually the idea behind this lock object in this case?
private static Service initializeEntryPoint() {
if (entryPoint == null) {
synchronized (Service.class) {
if (entryPoint == null) {
entryPoint = new Service();
}
}
}
return entryPoint;
}