Improvement - Use System.nanoTime() in IdleConnectionWatcher to avoid clock drifting #3367

pull/3384/head
Nikita Koksharov 4 years ago
parent 79c7397992
commit 5416a81137

@ -62,7 +62,7 @@ public class RedisConnection implements RedisCommands {
this.connectionPromise = connectionPromise;
updateChannel(channel);
lastUsageTime = System.currentTimeMillis();
lastUsageTime = System.nanoTime();
}
protected RedisConnection(RedisClient redisClient) {

@ -169,7 +169,7 @@ public class ClientConnectionsEntry {
return;
}
connection.setLastUsageTime(System.currentTimeMillis());
connection.setLastUsageTime(System.nanoTime());
freeConnections.add(connection);
}
@ -247,7 +247,7 @@ public class ClientConnectionsEntry {
return;
}
connection.setLastUsageTime(System.currentTimeMillis());
connection.setLastUsageTime(System.nanoTime());
freeSubscribeConnections.add(connection);
}

@ -63,14 +63,14 @@ public class IdleConnectionWatcher {
@Override
public void run() {
long currTime = System.currentTimeMillis();
long currTime = System.nanoTime();
for (Entry entry : entries) {
if (!validateAmount(entry)) {
continue;
}
for (RedisConnection c : entry.connections) {
long timeInPool = currTime - c.getLastUsageTime();
long timeInPool = TimeUnit.NANOSECONDS.toMillis(currTime - c.getLastUsageTime());
if (timeInPool > config.getIdleConnectionTimeout()
&& validateAmount(entry)
&& entry.deleteHandler.apply(c)) {

Loading…
Cancel
Save