ARTEMIS-1401 Numerical overflow fix when using System::nanoTime

This commit is contained in:
Francesco Nigro 2017-09-07 12:25:45 +02:00 committed by Clebert Suconic
parent 65a0c6104a
commit 35c3475092
3 changed files with 3 additions and 3 deletions

View File

@ -330,7 +330,7 @@ public class NettyConnection implements Connection {
parkNanos = 1000L;
}
boolean canWrite;
while (!(canWrite = canWrite(requiredCapacity)) && System.nanoTime() < deadline) {
while (!(canWrite = canWrite(requiredCapacity)) && (System.nanoTime() - deadline) < 0) {
//periodically check the connection state
checkConnectionState();
LockSupport.parkNanos(parkNanos);

View File

@ -386,7 +386,7 @@ public final class TimedBuffer {
lastFlushTime = System.nanoTime();
flush();
} else if (bufferObserver != null && System.nanoTime() > lastFlushTime + timeout) {
} else if (bufferObserver != null && System.nanoTime() - lastFlushTime > timeout) {
lastFlushTime = System.nanoTime();
// if not using flush we will spin and do the time checks manually
flush();

View File

@ -227,7 +227,7 @@ public class TimedBufferTest extends ActiveMQTestBase {
private static void spinSleep(long timeout) {
if (timeout > 0) {
final long deadline = System.nanoTime() + timeout;
while (System.nanoTime() < deadline) {
while (System.nanoTime() - deadline < 0) {
//spin wait
}
}