diff --git a/driver/src/main/java/com/impossibl/postgres/jdbc/PGDirectConnection.java b/driver/src/main/java/com/impossibl/postgres/jdbc/PGDirectConnection.java index a488e5427..8d16b6589 100644 --- a/driver/src/main/java/com/impossibl/postgres/jdbc/PGDirectConnection.java +++ b/driver/src/main/java/com/impossibl/postgres/jdbc/PGDirectConnection.java @@ -124,8 +124,8 @@ import java.sql.Savepoint; import java.sql.Struct; import java.text.ParseException; -import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -133,6 +133,7 @@ import java.util.Objects; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledFuture; @@ -178,11 +179,11 @@ public class PGDirectConnection extends BasicContext implements PGConnection { private static class Cleanup implements CleanupRunnable { ServerConnection serverConnection; - List> statements; + Collection> statements; StackTraceElement[] allocationStackTrace; String connectionInfo; - private Cleanup(ServerConnection serverConnection, List> statements, String connectionInfo) { + private Cleanup(ServerConnection serverConnection, Collection> statements, String connectionInfo) { this.serverConnection = serverConnection; this.statements = statements; this.allocationStackTrace = new Exception().getStackTrace(); @@ -217,7 +218,7 @@ public void run() { boolean autoCommit = true; private int networkTimeout; private SQLWarning warningChain; - private List> activeStatements; + private Collection> activeStatements; private Map descriptionCache; private Map preparedStatementCache; private int preparedStatementCacheThreshold; @@ -234,7 +235,7 @@ public void run() { this.strict = getSetting(STRICT_MODE); this.networkTimeout = getSetting(DEFAULT_NETWORK_TIMEOUT); - this.activeStatements = new ArrayList<>(); + this.activeStatements = new ConcurrentLinkedQueue<>(); this.notificationListeners = new ConcurrentHashMap<>(); final int descriptionCacheSize = getSetting(DESCRIPTION_CACHE_SIZE); @@ -394,7 +395,7 @@ else if (s == statement) { * * @param statements Statements to close */ - private static void closeStatements(List> statements) { + private static void closeStatements(Collection> statements) { for (WeakReference statementRef : statements) { diff --git a/driver/src/main/java/com/impossibl/postgres/jdbc/PGStatement.java b/driver/src/main/java/com/impossibl/postgres/jdbc/PGStatement.java index f686808de..a9ef5cff0 100644 --- a/driver/src/main/java/com/impossibl/postgres/jdbc/PGStatement.java +++ b/driver/src/main/java/com/impossibl/postgres/jdbc/PGStatement.java @@ -48,10 +48,11 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.Statement; -import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; import static java.lang.Long.min; import static java.util.concurrent.TimeUnit.SECONDS; @@ -74,10 +75,10 @@ private static class Cleanup implements CleanupRunnable { PGDirectConnection connection; String name; - List> resultSets; + Collection> resultSets; StackTraceElement[] allocationStackTrace; - private Cleanup(PGDirectConnection connection, String name, List> resultSets) { + private Cleanup(PGDirectConnection connection, String name, Collection> resultSets) { this.connection = connection; this.name = name; this.resultSets = resultSets; @@ -129,7 +130,7 @@ public void run() { Query query; List resultBatches; boolean autoClose; - List> activeResultSets; + Collection> activeResultSets; PGResultSet generatedKeysResultSet; SQLWarning warningChain; int queryTimeout; @@ -148,7 +149,7 @@ public void run() { this.name = name; this.processEscapes = true; this.resultFields = resultFields; - this.activeResultSets = new ArrayList<>(); + this.activeResultSets = new ConcurrentLinkedQueue<>(); this.generatedKeysResultSet = null; this.fetchSize = connection.getDefaultFetchSize(); @@ -199,7 +200,7 @@ static void closeCursor(PGDirectConnection connection, String cursorName) throws * Closes the given list of result-sets * */ - private static void closeResultSets(List> resultSets) { + private static void closeResultSets(Collection> resultSets) { for (WeakReference resultSetRef : resultSets) {