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. Remember that 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.




Does synchronizing a constructor make sense?

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. In other words, there is no need to switch out of the constructor to another thread. Also, when the constructor is called, the object does not even exist yet.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.