This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Synchronization of a block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Synchronization of a block" Watch "Synchronization of a block" New topic
Author

Synchronization of a block

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
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

Joined: Oct 19, 2002
Posts: 23
the object is sychronized only one thread can get the object lock at a time.
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
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

Joined: Oct 19, 2002
Posts: 23
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

Joined: Dec 05, 2000
Posts: 231
thanks
 
 
subject: Synchronization of a block