|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfr.xephi.authme.datasource.MiniConnectionPoolManager
public class MiniConnectionPoolManager
A lightweight standalone JDBC connection pool manager.
The public methods of this class are thread-safe.
Home page: www.
source-code.biz/miniconnectionpoolmanager
Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
Multi-licensed: EPL / LGPL / MPL.
| Nested Class Summary | |
|---|---|
static class |
MiniConnectionPoolManager.TimeoutException
Thrown in getConnection() or getValidConnection() when
no free connection becomes available within timeout seconds. |
| Constructor Summary | |
|---|---|
MiniConnectionPoolManager(javax.sql.ConnectionPoolDataSource dataSource,
int maxConnections)
Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds. |
|
MiniConnectionPoolManager(javax.sql.ConnectionPoolDataSource dataSource,
int maxConnections,
int timeout)
Constructs a MiniConnectionPoolManager object. |
|
| Method Summary | |
|---|---|
void |
dispose()
Closes all unused pooled connections. |
int |
getActiveConnections()
Returns the number of active (open) connections of this pool. |
java.sql.Connection |
getConnection()
Retrieves a connection from the connection pool. |
int |
getInactiveConnections()
Returns the number of inactive (unused) connections in this pool. |
java.sql.Connection |
getValidConnection()
Retrieves a connection from the connection pool and ensures that it is valid by calling Connection.isValid(int). |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MiniConnectionPoolManager(javax.sql.ConnectionPoolDataSource dataSource,
int maxConnections)
dataSource - the data source for the connections.maxConnections - the maximum number of connections.
public MiniConnectionPoolManager(javax.sql.ConnectionPoolDataSource dataSource,
int maxConnections,
int timeout)
dataSource - the data source for the connections.maxConnections - the maximum number of connections.timeout - the maximum time in seconds to wait for a free connection.| Method Detail |
|---|
public void dispose()
throws java.sql.SQLException
java.sql.SQLException
public java.sql.Connection getConnection()
throws java.sql.SQLException
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.
Connection object.
MiniConnectionPoolManager.TimeoutException - when no connection becomes available within
timeout seconds.
java.sql.SQLExceptionpublic java.sql.Connection getValidConnection()
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 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.
MiniConnectionPoolManager.TimeoutException - when no valid connection becomes available within
timeout seconds.public int getActiveConnections()
This is the number of Connection objects that have been
issued by getConnection(), for which
Connection.close() has not yet been called.
public int getInactiveConnections()
This is the number of internally kept recycled connections, for which
Connection.close() has been called and which have not yet
been reused.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||