If there is no thread which is waiting, using Object.wait() , any calls to Object.notify() or Object.notifyAll() have no effect. I have a scenario in which if I call Object.notify() when the wait set is empty, a subsequent call to Object.wait() should not put the thread to wait. How can this be accomplished? Semaphores may be one solution I can think of. Is there a more elegant solution?
This kind of scenario seems to be a perfect fit for a Semaphore. Call Semaphore.release() instead of notify() and Semaphore.acquire() instead of wait.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With