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
Question
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
Solution
The correct answer is "Calling wait() method on an object".
Here's why:
-
The wait() method is used in threading in Java. It causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. So, it essentially stops the execution of the current thread.
-
The notify() method wakes up a single thread that is waiting on this object's monitor. It does not stop the execution of a thread.
-
The setPriority() method changes the priority of the thread. This doesn't stop the execution of a thread, it just determines the order in which threads are executed.
-
The read() method of InputStream class in Java is used to read the next byte of data from the input stream. It blocks until input data is available, the end of the stream is detected, or an exception is thrown. It doesn't stop the execution of a thread.
Similar Questions
Select the correct answerWhich of these method of Thread class is used to Suspend a thread for a period of time?Optionssuspend()terminate()sleep()stop()
Select the correct answerWhich of the following will ensure the thread will be in running state?Optionsyield()wait()Thread.killThread()notify()
Select the correct answerWhich of these method waits for the thread to terminate?Optionsjoin()isAlive()sleep()stop()
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 is used to explicitly set the priority of a thread?OptionssetPriority()make()set()makePriority()
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.