This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization of a block

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a little confused about which objects do we synchronize when we synchronize a code block.
When we synchronize a method, is the method synchronized or the object?
 
El Roy Cabildo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the object is sychronized only one thread can get the object lock at a time.
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generally what type of objects do we synchronize, the class which implements the Runnable interface or any object which holds important data ??
 
El Roy Cabildo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well it depends on you...if you are designing as system that only one thread can access then sychronized it....imagine if you have a application which deals banking...threads can freelyy withdraw and deposits... try this link...http://java.sun.com/docs/books/tutorial/essential/threads/index.html
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic