changeset 8481:7dd39219bd68

Connection pool: do not wait forever for new connections and be more verbose.
author Tom Gottfried <tom@intevation.de>
date Thu, 27 Nov 2014 19:55:55 +0100
parents 3cfa0af6fa2a
children 0c22ef71d154
files backend/src/main/java/org/dive4elements/river/backend/utils/DBCPConnectionProvider.java
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/backend/utils/DBCPConnectionProvider.java	Thu Nov 27 19:14:05 2014 +0100
+++ b/backend/src/main/java/org/dive4elements/river/backend/utils/DBCPConnectionProvider.java	Thu Nov 27 19:55:55 2014 +0100
@@ -215,6 +215,7 @@
             String validationQuery = props.getProperty("validationQuery");
             if (validationQuery != null) {
                 ds.setValidationQuery(validationQuery);
+                ds.setMaxWait(1000); //TODO: make it configurable
             }
             // The BasicDataSource has lazy initialization
             // borrowing a connection will start the DataSource
@@ -240,10 +241,20 @@
     }
 
     public Connection getConnection() throws SQLException {
-        return ds.getConnection();
+        log.debug("Connection pool parameters:");
+        log.debug("_ active connections: " + ds.getNumActive());
+        log.debug("_ idle connections: " + ds.getNumIdle());
+        log.debug("_ max active: " + ds.getMaxActive());
+        if (ds.getNumActive() == ds.getMaxActive()) {
+            log.warn("Maximum number of database connections in pool in use!");
+        }
+        Connection conn = ds.getConnection();
+        log.debug("Return connection with hash: " + conn.hashCode());
+        return conn;
     }
 
     public void closeConnection(Connection conn) throws SQLException {
+        log.debug("Close connection with hash: " + conn.hashCode());
         conn.close();
     }
 

http://dive4elements.wald.intevation.org