Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help on synchronized

 
Mike Liu
Greenhorn
Posts: 3
  • 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
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic