jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes need help on synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need help on synchronized" Watch "need help on synchronized" New topic
Author

need help on synchronized

Mike Liu
Greenhorn

Joined: Jan 24, 2002
Posts: 3
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

Joined: Jan 18, 2002
Posts: 178
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.


<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help on synchronized
 
Similar Threads
Synchronized block K&B problem
4m Dan's Exam
About the problem of producer and consumer
Why this synchronization doesn't work
comparing chars