Learnitweb

Can a constructor be synchronized in Java?

Constructors cannot be synchronized. Using the synchronized keyword with a constructor is a syntax error – Illegal modifier for the constructor in type your class name; only public, protected & private are permitted’.

Synchronizing constructors doesn’t make sense, because only the thread that creates an object should have access to it while it is being constructed. Constructors cannot be marked synchronized because other threads cannot see the object being created until the thread creating it has finished it.

According to the JLS:

There is no practical need for a constructor to be synchronized, because it would lock the object under construction, which is normally not made available to other threads until all constructors for the object have completed their work.