which is better notify() or notifyAll() ?

Hello ,

i know that notify() is responsible to wake up on of the threads waiting to access object and notifyAll() responsible to wake up all threads waiting to access same object but what it is the other different between these two methods ? and which is better ?

Thanks a lot

[303 byte] By [nadaqam] at [2007-9-26 1:54:17]
# 1
Check out the Javadocs for the Object class at: http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.htmlnotify() will only wake up one thread, notifyAll() wakes 'em all up.Yours,Tom
tcopeland at 2007-6-29 3:06:32 > top of Java-index,Archived Forums,Java Programming...
# 2

If there are n number of threads in a wait() mode then the notify() method wakes up or sends the notification to the nth thread that went in the wait() mode in the last. So, only the last thread that went into the wait() mode wakes up out of all the waiting threads. However, in case of notifyAll() the notification is sent to all the waiting threads that are waiting. So, any one of them may come out of the wait() mode depending upon the priority and other factors, like the kind of multitasking supported by the operating system( preemptive or collaborative).

kmsr1 at 2007-6-29 3:06:32 > top of Java-index,Archived Forums,Java Programming...