synchronized(this) will capture lock from the present object while synchronized(new c()) will always create new object and capture lock from that object which means that two threads will always enter in the block.
Thank You for Your reply,so if I give synchronized(c) then any thread entering this block will acquire the lock from object C
and it will be the monitoring object instead of the this object . will there be any difference based on the monitoring object
Ramaswamy Narayanan O.B wrote:.. ,so if I give synchronized(c) then any thread entering this block will acquire the lock from object C
and it will be the monitoring object instead of the this object .
Yes.
will there be any difference based on the monitoring object
It may depends on the requirement whether to synchronized on the current instance (i.e: this) or any shared instance. But what ever used that object's lock should be aquired by the calling thread.