Two Laptop Bag
The moose likes Threads and Synchronization and the fly likes Difference in Synchronize and wait-notify Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Difference in Synchronize and wait-notify" Watch "Difference in Synchronize and wait-notify" New topic
Author

Difference in Synchronize and wait-notify

Vishnu Sharma
Ranch Hand

Joined: Feb 03, 2010
Posts: 55
What is exact difference in between these two approaches?? Synchronize is doing the same thing, it holds the object lock and says to the another thread to wait. When it releases the object lock, it is notifying the other thread, that it can now use the object.


Regards,
Vishnu
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16685
    
  19


The synchronization mechanism and wait-notify mechanism are not different ways of doing the same thing. In fact, wait-notify depends on synchronization. In "threads speak", the first is an implementation of a mutex, and the second is a implementation of a condition variable.

The Sun tutorial on threads is a good start to learn the topic.

http://java.sun.com/docs/books/tutorial/essential/concurrency/

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vishnu Sharma
Ranch Hand

Joined: Feb 03, 2010
Posts: 55
Henry Wong wrote:
The synchronization mechanism and wait-notify mechanism are not different ways of doing the same thing. In fact, wait-notify depends on synchronization. In "threads speak", the first is an implementation of a mutex, and the second is a implementation of a condition variable.

The Sun tutorial on threads is a good start to learn the topic.

http://java.sun.com/docs/books/tutorial/essential/concurrency/

Henry


Thanks Henry.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Difference in Synchronize and wait-notify
 
Similar Threads
difference between wait() and sleep()
wait() and waitForAll()
Synchronization Problem
Difference between synchronized(this) and synchronized(other external object)
why a wait call should be from a synchronized block?