Which Methods May Cause a Thread to Stop Executing?

By BYJU'S Exam Prep

Updated on: September 25th, 2023

Which methods may cause a thread to stop executing?

  1. wait()
  2. notify()
  3. notifyall()
  4. exits synchronized code

Answer A. wait().

The wait() may cause a thread to stop executing.


Option A is correct.  The wait() method makes the active thread wait until another thread calls this object’s notify() or notifyAll() methods.

Option B is incorrect. A single thread waiting on this object’s monitor is awakened by the notify() function.

Option C is incorrect. Notifies every thread that is waiting on this object’s monitor by calling notifyAll().

Option D is incorrect. The thread holding the lock or the thread in the synchronized method typically quits the synchronized method when a lock is released. The lock is released when another thread enters a synchronized procedure on that object. Does executing threads halt while entering or leaving synchronized code? Not required, as the thread can still execute unsynchronized code. The word directly in the question, in my opinion, gives us a hint. The execution of a thread is not immediately stopped when synchronized code is exited.

☛ Related Questions:


Our Apps Playstore
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303
Home Practice Test Series Premium