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; this.connectionPromise = connectionPromise;
updateChannel(channel); updateChannel(channel);
lastUsageTime = System.currentTimeMillis(); lastUsageTime = System.nanoTime();
} }
protected RedisConnection(RedisClient redisClient) { protected RedisConnection(RedisClient redisClient) {

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

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

Loading…
Cancel
Save