JD.LOCK.SLEEP occurs when a method calls Thread.sleep() while a lock is held.

Vulnerability and risk

This may result in very poor performance and scalability, or in a deadlock, since other threads may be waiting to acquire the lock. It is a much better idea to call wait() on the lock, which releases the lock and allows other threads to run.

Mitigation and prevention

Call a sleep() method without holding locks.

Example 1

13     String name;
14     synchronized void finish(Object o) throws InterruptedException {
15         while (!name.equals("root")) {
16             Thread.sleep(1000);
17         }
18     }

JD.LOCK.SLEEP is reported for line 16: Calling 'java.lang.Thread.sleep(long)' with locks '[this]' held could cause a deadlock.

Related checkers