Select the correct answerWhich of the following will ensure the thread will be in running state?Optionsyield()wait()Thread.killThread()notify()
Question
Select the correct answerWhich of the following will ensure the thread will be in running state?Optionsyield()wait()Thread.killThread()notify()
Solution
The correct answer is notify().
Here's why:
-
yield(): This method causes the currently executing thread object to temporarily pause and allow other threads to execute.
-
wait(): This method tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify().
-
Thread.killThread(): This method does not exist in Java.
-
notify(): This method wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. So, this is the method that will ensure the thread will be in running state.
Similar Questions
Select the correct answerWhich of this method is used to find out that a thread is still running or not?OptionsisAlive()Alive()run()checkRun()
Select the correct answerWhich of these method waits for the thread to terminate?Optionsjoin()isAlive()sleep()stop()
Select the correct answerWhich of these method wakes up the first thread that called wait()?Optionsstart()notify()wake()notifyAll()
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()
Select the correct answerWhich of the following stops execution of a thread?OptionsCalling wait() method on an objectCalling notify() method on an objectCalling SetPriority() method on a Thread objectCalling read() method on an InputStream object
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.