aspose file tools*
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
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Synchronization of a block