Manages a pool of database connections. In addition, DBPool configures
the database connection from a configuration file.
Like JDBC 2.0 pooling, DBPool returns a wrapped Connection.
Applications can use that connection just like an unpooled connection.
It is more important than ever to close() the connection,
because the close returns the connection to the connection pool.
Example using DataSource JNDI style (recommended)
Context env = (Context) new InitialContext().lookup("java:comp/env");
DataSource pool = (DataSource) env.lookup("jdbc/test");
Connection conn = pool.getConnection();
try {
... // normal connection stuff
} finally {
conn.close();
}
The pool will only allow getMaxConnections() connections alive at a time.
If getMaxConnection connections are already active,
getPooledConnection will block waiting for an available
connection. The wait is timed. If connection-wait-time passes
and there is still no connection, getPooledConnection
create a new connection anyway.
Connections will only stay in the pool for about 5 seconds. After
that they will be removed and closed. This reduces the load on the DB
and also protects against the database dropping old connections.