advancedMultithreading & Concurrency227 of 436
wait vs sleep. How can incorrect usage lead to deadlocks?
Tests whether you know sleep() holds any locks the thread owns for its entire duration, so sleeping while holding a lock another thread needs can create a deadlock-like stall, while wait() correctly releases the monitor -- and whether you know an improperly guarded wait() (missing the notify, or checking the condition outside a loop) can leave a thread waiting forever.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response