When a method is synchronized thread acquires a lock on current instance on which method was called. In multithreaded environment there are chances that a same instance is used by multiple threads. so, synchronized is basically to prevent same resource being accessed by multiple threads simultaneously.
When we call constructor anyways we are creating a new instance. If multiple threads call the same constructor then they are working on different instances anyways, so there is no point in using keyword synchronized along with constructor.
In Singleton Pattern, you want only one instance to be created, constructor is private and very importantly the helper method that returns the instance of the class must be made synchronized so that in multi-threaded environment no two threads could access that method simultaneously otherwise the method could end returning two different objects.
The shape of the Singleton class looks like:
Still cloning gotcha is there, to tackle with that, you should override the clone() method and throw CloneNotSupportedException from that.
Originally posted by Raghavan Muthu: But would there be a situation in a multi-threaded environment where in you need to synchronize the object creation? If at all, we have a pattern called Singleton for it.
As was said before, constructors do not need to be synchronized. Singletons have nothing to do with this.