Symantec Interview Question
Senior Software Development EngineersCountry: India
I am not aware of these methods in Java. but as far as my understanding of POSIX pthread API, these are same as pthread_cond_wait, pthread_cond_signal and pthread_cond_broadcast respectively. In case we consider POSIX semaphores, then these are equivalent to sem_wait and sem_post (there is no sem_broadcast operation).
The .wait() method waits on the object it's being called on, until the .notify() method is called on that object at which point the waiting thread is woken. Notify only wakes one thread waiting on the object, whereas notifyAll wakes all of them.
- Anonymous April 05, 2013Wait/Notify is useful when a thread needs access to a resource or data which is not yet available. One option would be to have a busy loop which keeps polling the data or resource until it's available, but that would just be wasting CPU cycles. With notify the thread can be suspended until the data or resource is available.