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

     String name;
     synchronized void finish(Object o) throws InterruptedException {
         while (!name.equals("root")) {

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

Related checkers