File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help on synchronized

 
Mike Liu
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can some one explain the difference between the following methods?
public void push(char c){
synchronized(this){
\\code
}
}
public synchronized push(char c){
\\code
}
thanks for helping me out
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it's not obvious, one sync's on the current object in a code block and the other sync's on the current object during the entire execution of the method.
The first is a more fine-grain way to perform sync's on shared resources.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic