This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

object locking  RSS feed

 
Ramaswamy Narayanan O.B
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
paresha bhavsar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ramaswamy Narayanan O.B
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!