postgresql-jdbc.git / summary / log / commit / refs

commit    ff4a66d29d863cb4a6d2aecee2faec424f8d51d7
Author:   Dave Cramer <davecramer@gmail.com>
Commit:   GitHub <noreply@github.com>
Date:     Tue Nov 26 14:37:05 2019 +0000

    fix: remove currentTimeMillis from code, tests are OK (#1617)


pgjdbc/src/main/java/org/postgresql/Driver.java | 4 ++-- pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java | 4 ++-- .../java/org/postgresql/hostchooser/GlobalHostStatusTracker.java | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pgjdbc/src/main/java/org/postgresql/Driver.java b/pgjdbc/src/main/java/org/postgresql/Driver.java index f540d606..3f6fbba9 100644 --- a/pgjdbc/src/main/java/org/postgresql/Driver.java +++ b/pgjdbc/src/main/java/org/postgresql/Driver.java @@ -397,7 +397,7 @@ public class Driver implements java.sql.Driver { * @throws SQLException if a connection error occurs or the timeout is reached */ public Connection getResult(long timeout) throws SQLException { - long expiry = System.currentTimeMillis() + timeout; + long expiry = System.nanoTime() / 1000 + timeout; synchronized (this) { while (true) { if (result != null) { @@ -416,7 +416,7 @@ public class Driver implements java.sql.Driver { } } - long delay = expiry - System.currentTimeMillis(); + long delay = expiry - System.nanoTime() / 1000; if (delay <= 0) { abandoned = true; throw new PSQLException(GT.tr("Connection attempt timed out."), diff --git a/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java b/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java index 4e85f02a..c944ca03 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java +++ b/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java @@ -717,7 +717,7 @@ public class QueryExecutorImpl extends QueryExecutorBase { long startTime = 0; int oldTimeout = 0; if (useTimeout) { - startTime = System.currentTimeMillis(); + startTime = System.nanoTime() / 1000; try { oldTimeout = pgStream.getSocket().getSoTimeout(); } catch (SocketException e) { @@ -747,7 +747,7 @@ public class QueryExecutorImpl extends QueryExecutorBase { SQLWarning warning = receiveNoticeResponse(); addWarning(warning); if (useTimeout) { - long newTimeMillis = System.currentTimeMillis(); + long newTimeMillis = System.nanoTime() / 1000; timeoutMillis += startTime - newTimeMillis; // Overflows after 49 days, ignore that startTime = newTimeMillis; if (timeoutMillis == 0) { diff --git a/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java b/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java index bd53ab93..0ba547bc 100644 --- a/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java +++ b/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java @@ -5,8 +5,6 @@ package org.postgresql.hostchooser; -import static java.lang.System.currentTimeMillis; - import org.postgresql.util.HostSpec; import java.util.ArrayList; @@ -28,7 +26,7 @@ public class GlobalHostStatusTracker { * @param hostStatus Latest known status for the host. */ public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) { - long now = currentTimeMillis(); + long now = System.nanoTime() / 1000; synchronized (hostStatusMap) { HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec); if (hostSpecStatus == null) { @@ -51,7 +49,7 @@ public class GlobalHostStatusTracker { static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs, HostRequirement targetServerType, long hostRecheckMillis) { List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length); - long latestAllowedUpdate = currentTimeMillis() - hostRecheckMillis; + long latestAllowedUpdate = System.nanoTime() / 1000 - hostRecheckMillis; synchronized (hostStatusMap) { for (HostSpec hostSpec : hostSpecs) { HostSpecStatus hostInfo = hostStatusMap.get(hostSpec); [parent: 9a193de71d3e]