postgresql-jdbc.git / summary / log / commit / refs
commit dca9727ef5f1fb36c4a5ab0ff47c5201ff6d0327
Author: Sehrope Sarkuni <sehrope@jackdb.com>
Date: Sat Oct 04 19:11:59 2014 +0000
Change TimerTask methods to be called through the Connection
Change all references to addTimerTask(...) and purgeTimerTasks() to go through the Connection object.
This removes any direct references to the TimerTask related methods in Driver from the rest of the driver.
The new addTimerTask(...) and purgeTimerTask() methods in AbstractJdbc2Connection still use the shared static Timer in Driver.
org/postgresql/Driver.java.in | 9 +++++----
org/postgresql/core/BaseConnection.java | 12 ++++++++++++
org/postgresql/jdbc2/AbstractJdbc2Connection.java | 9 +++++++++
org/postgresql/jdbc2/AbstractJdbc2Statement.java | 5 ++---
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/org/postgresql/Driver.java.in b/org/postgresql/Driver.java.in
index 9b6b3d0a..251a2a8d 100644
--- a/org/postgresql/Driver.java.in
+++ b/org/postgresql/Driver.java.in
@@ -768,9 +768,10 @@ public class Driver implements java.sql.Driver
if ( cancelTimer != null ) cancelTimer.purge();
}
- public static void addTimerTask(TimerTask timerTask, long milliSeconds)
- {
- cancelTimer.schedule( timerTask, milliSeconds );
+ /**
+ * Return the static shared Timer.
+ */
+ public static Timer getTimer() {
+ return cancelTimer;
}
-
}
diff --git a/org/postgresql/core/BaseConnection.java b/org/postgresql/core/BaseConnection.java
index 999e0a2b..8ffa1ace 100644
--- a/org/postgresql/core/BaseConnection.java
+++ b/org/postgresql/core/BaseConnection.java
@@ -7,6 +7,7 @@
*/
package org.postgresql.core;
+import java.util.TimerTask;
import java.sql.*;
import org.postgresql.PGConnection;
import org.postgresql.jdbc2.TimestampUtils;
@@ -196,4 +197,15 @@ public interface BaseConnection extends PGConnection, Connection
* Return whether to disable column name sanitization.
*/
public boolean isColumnSanitiserDisabled();
+
+ /**
+ * Schedule a TimerTask for later execution.
+ * The task will be scheduled with the shared Timer for this connection.
+ */
+ public void addTimerTask(TimerTask timerTask, long milliSeconds);
+
+ /**
+ * Invoke purge() on the underlying shared Timer so that internal resources will be released.
+ */
+ public void purgeTimerTasks();
}
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index 87902f18..b5bfd5eb 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -1324,4 +1324,13 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
{
protoConnection.abort();
}
+
+ public void addTimerTask(TimerTask timerTask, long milliSeconds) {
+ Timer cancelTimer = Driver.getTimer();
+ cancelTimer.schedule( timerTask, milliSeconds );
+ }
+
+ public void purgeTimerTasks() {
+ Driver.purgeTimerTasks();
+ }
}
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index bfcc9d99..ce387ca1 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3439,7 +3439,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
}
};
- Driver.addTimerTask(cancelTimerTask, timeout * 1000);
+ connection.addTimerTask(cancelTimerTask, timeout * 1000);
}
private synchronized void killTimerTask()
@@ -3447,9 +3447,8 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
if (cancelTimerTask != null) {
cancelTimerTask.cancel();
cancelTimerTask = null;
- Driver.purgeTimerTasks();
+ connection.purgeTimerTasks();
}
-
}
protected boolean getForceBinaryTransfer()
[parent: dd366acde4f6]