Repeating my response due to the subject mangling in the other "thread":
This is a known issue:
https://bugs.openjdk.java.net/browse/JDK-6900441
fixed in 7u60, 8 and 9.
What version were you running?
David
On 7/11/2014 6:22 PM, wuwen.55 wrote:
call .await(10, TimeUnit.SECONDS) and change the time one hours back.
i.e. start at 13:00 call .await and at 13:05 change the time to 12:05
you will notice that the wait does not return.
when change the time to the current time . change the time to 13:05.
the wait still does not return.
test code:
CountDownLatch c = new CountDownLatch(1);
...
c.await(10, TimeUnit.SECONDS);
...
----------------------------------
AbstractQueuedSynchronizer.doAcquireNanos
long lastTime = System.nanoTime();
final Node node = addWaiter(Node.EXCLUSIVE);
boolean failed = true;
try {
for (;;) {
final Node p = node.predecessor();
if (p == head && tryAcquire(arg)) {
setHead(node);
p.next = null; // help GC
failed = false;
return true;
}
if (nanosTimeout <= 0)
return false;
if (shouldParkAfterFailedAcquire(p, node) &&
nanosTimeout > spinForTimeoutThreshold)
LockSupport.parkNanos(this, nanosTimeout);
long now = System.nanoTime();
nanosTimeout -= now - lastTime;
lastTime = now;
if (Thread.interrupted())
throw new InterruptedException();
}
} finally {
if (failed)
cancelAcquire(node);
}
when change the time one hours back
now - lastTime is negative number.
—————————