If you want to make sure that the code block inside your constructor is never executed by more than one thread at a time, you can synchronize it with the class, for example ...
public class MyClass { public MyClass() { synchronized(MyClass.class) {
You do not need to use "MyClass.class", if you do not want this, you may have a "LOCK" object, for example ...
public class MyClass { private static final Object LOCK = new Object(); public MyClass() { synchronized(LOCK) {
Bretc source share