Failed waiters could wait longer than the requested timeout (upto 2x)

This commit is contained in:
Chiradeep Vittal 2011-08-18 12:06:19 -07:00
parent 3a087c2e62
commit eca3d1cb90
1 changed files with 9 additions and 4 deletions

View File

@ -132,15 +132,20 @@ public class GlobalLock {
if(ownerThread != null) {
profiler.start();
try {
wait(((long)timeoutSeconds)*1000L);
wait((long)remainingMilliSeconds);
} catch (InterruptedException e) {
interrupted = true;
}
profiler.stop();
remainingMilliSeconds -= profiler.getDuration();
if(remainingMilliSeconds < 0)
return false;
remainingMilliSeconds -= profiler.getDuration();
//if equal to zero, then it could come back to the wait and wait
//forever since wait(0) waits till interrupted or notified.
if (remainingMilliSeconds <= 0) {
if (s_logger.isTraceEnabled())
s_logger.trace("timed out waiting for " + name + " last wait duration=" + profiler.getDuration());
return false;
}
continue;
} else {