Calling sleep()
while holding a lock can cause a loss of performance and might cause a deadlock.
If multiple threads are trying to obtain a lock on a resource, calling sleep()
while holding a lock can cause all of the other threads to wait for the resource to be released, which can result in degraded performance and deadlock.
Example 1: The following code calls sleep()
while holding a lock.
ReentrantLock rl = new ReentrantLock();
...
rl.lock();
Thread.sleep(500);
...
rl.unlock();
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A9 Application Denial of Service
[2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP6080 CAT II
[3] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 557
[4] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9