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.
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.
Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.
Link to this page:
Please bookmark with social media, your votes are noticed and appreciated: