Knowee
Questions
Features
Study Tools

A monitor called mon has 5 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from Waiting state to Ready State?AExecute notify(thread1); from within synchronized code of monBExecute mon.notify(thread1); from synchronized code of any object.CExecute thread1.notify(); from synchronized code of any object.DExecute thread1.notify(); from any code(synchronized or not) of any object.EYou cannot specify which thread will get notified.

Question

A monitor called mon has 5 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from Waiting state to Ready State?AExecute notify(thread1); from within synchronized code of monBExecute mon.notify(thread1); from synchronized code of any object.CExecute thread1.notify(); from synchronized code of any object.DExecute thread1.notify(); from any code(synchronized or not) of any object.EYou cannot specify which thread will get notified.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is E. You cannot specify which thread will get notified.

In Java, the notify() or notifyAll() methods are used to wake up threads that are waiting on the object's monitor. However, you cannot specify which thread to wake up. The choice is arbitrary and comes from the thread scheduling mechanism.

When notify() is called, it wakes up one of the waiting threads. When notifyAll() is called, it wakes up all the waiting threads. But in both cases, you cannot control or predict which thread(s) will be chosen.

So, if you have multiple threads with the same priority waiting on a monitor, calling notify() or notifyAll() will not guarantee that a specific thread (like thread1 in your question) will be the one to wake up.

This problem has been solved

Similar Questions

Select the correct answerWhich of these method is used to tell the calling thread to give up a monitor and go to sleep until some other thread enters the same monitor?OptionsnotifyAll()notify()wait()sleep()

ct answerWhich of the following will ensure the thread will be in running state?Optionsyield()wait()notify()Thread.killThread()

Select the correct answerWhich of these method wakes up the first thread that called wait()?Optionsstart()notify()wake()notifyAll()

Which class in the threading module provides a mechanism to synchronize threads by making them wait for each other?SemaphoreBarrierEventCondition

Select the correct answerWhich of these method wakes up all the threads?Optionsstart()notify()wakeAll()notifyAll()

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.