ConnectionPool Class

A lightweight standalone JDBC connection pool manager.

Constructors

ConnectionPool( Database database, int maxConnections )
ConnectionPool( Database database, int maxConnections, int timeout )
ConnectionPool( ConnectionPoolDataSource dataSource, int maxConnections )
ConnectionPool( ConnectionPoolDataSource dataSource, int maxConnections, Integer timeout )

Public Methods

close( ) returns synchronized void
Closes all unused pooled connections.
getConnection( ) returns Connection
Retrieves a connection from the connection pool.

If maxConnections connections are already in use, the method waits until a connection becomes available or timeout seconds elapsed. When the application is finished using the connection, it must close it in order to return it to the pool.

getValidConnection( ) returns Connection
Retrieves a connection from the connection pool and ensures that it is valid by calling {@link Connection#isValid(int)}.

If a connection is not valid, the method tries to get another connection until one is valid (or a timeout occurs).

Pooled connections may become invalid when e.g. the database server is restarted.

This method is slower than {@link #getConnection()} because the JDBC driver has to send an extra command to the database server to test the connection.

This method requires Java 1.6 or newer.

getActiveConnections( ) returns synchronized int
Returns the number of active (open) connections of this pool.

This is the number of Connection objects that have been issued by {@link #getConnection()}, for which Connection.close() has not yet been called.

getInactiveConnections( ) returns synchronized int
Returns the number of inactive (unused) connections in this pool.

This is the number of internally kept recycled connections, for which Connection.close() has been called and which have not yet been reused.

getMaxConnections( ) returns int
getConnectionPoolDataSource( ) returns ConnectionPoolDataSource
getTimeout( ) returns int

Public Classes