Inspectopedia
 
2024.3

Call to 'Thread.sleep()' while synchronized

Warning
New
Last modified: 03 December 2024

Reports calls to java.lang.Thread.sleep() methods that occur within a synchronized block or method.

sleep() within a synchronized block may result in decreased performance, poor scalability, and possibly even deadlocking. Consider using wait() instead, as it will release the lock held.

Example: