Can constructors be synchronized in Java?
No, constructors can not be synchronized in Java. In fact using the keyword “synchronized” with a constructor is actually a syntax error.
The “synchronized” keyword is used to prevent 2 or more threads from accessing a group of methods before one thread finishes execution in those methods.
Synchronizing a constructor does not make sense simply because only one thread needs to have access to a constructor. Only the thread that creates an object needs to have access to it while it is being constructed.
when the constructor is called, the object does not even exist yet.
Read full article from Can constructors be synchronized in Java?
No, constructors can not be synchronized in Java. In fact using the keyword “synchronized” with a constructor is actually a syntax error.
The “synchronized” keyword is used to prevent 2 or more threads from accessing a group of methods before one thread finishes execution in those methods.
Synchronizing a constructor does not make sense simply because only one thread needs to have access to a constructor. Only the thread that creates an object needs to have access to it while it is being constructed.
when the constructor is called, the object does not even exist yet.
Read full article from Can constructors be synchronized in Java?