comparison backend/src/main/java/org/dive4elements/river/backend/utils/DBCPConnectionProvider.java @ 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 c5a7aae52396
children 8c615d738e84
comparison
equal deleted inserted replaced
8480:3cfa0af6fa2a 8481:7dd39219bd68
213 } 213 }
214 214
215 String validationQuery = props.getProperty("validationQuery"); 215 String validationQuery = props.getProperty("validationQuery");
216 if (validationQuery != null) { 216 if (validationQuery != null) {
217 ds.setValidationQuery(validationQuery); 217 ds.setValidationQuery(validationQuery);
218 ds.setMaxWait(1000); //TODO: make it configurable
218 } 219 }
219 // The BasicDataSource has lazy initialization 220 // The BasicDataSource has lazy initialization
220 // borrowing a connection will start the DataSource 221 // borrowing a connection will start the DataSource
221 // and make sure it is configured correctly. 222 // and make sure it is configured correctly.
222 223
238 } 239 }
239 log.debug("Configure DBCPConnectionProvider complete"); 240 log.debug("Configure DBCPConnectionProvider complete");
240 } 241 }
241 242
242 public Connection getConnection() throws SQLException { 243 public Connection getConnection() throws SQLException {
243 return ds.getConnection(); 244 log.debug("Connection pool parameters:");
245 log.debug("_ active connections: " + ds.getNumActive());
246 log.debug("_ idle connections: " + ds.getNumIdle());
247 log.debug("_ max active: " + ds.getMaxActive());
248 if (ds.getNumActive() == ds.getMaxActive()) {
249 log.warn("Maximum number of database connections in pool in use!");
250 }
251 Connection conn = ds.getConnection();
252 log.debug("Return connection with hash: " + conn.hashCode());
253 return conn;
244 } 254 }
245 255
246 public void closeConnection(Connection conn) throws SQLException { 256 public void closeConnection(Connection conn) throws SQLException {
257 log.debug("Close connection with hash: " + conn.hashCode());
247 conn.close(); 258 conn.close();
248 } 259 }
249 260
250 public void close() throws HibernateException { 261 public void close() throws HibernateException {
251 try { 262 try {

http://dive4elements.wald.intevation.org