Package ca.phon.ipadictionary.impl
Class MiniConnectionPoolManager
java.lang.Object
ca.phon.ipadictionary.impl.MiniConnectionPoolManager
A simple standalone JDBC connection pool manager.
The public methods of this class are thread-safe.
Author: Christian d'Heureuse
(www.source-code.biz)
Multi-licensed: EPL/LGPL/MPL.
2007-06-21: Constructor with a timeout parameter added.
2008-05-03: Additional licenses added (EPL/MPL).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Thrown ingetConnection()
when no free connection becomes available withintimeout
seconds. -
Constructor Summary
ConstructorDescriptionMiniConnectionPoolManager
(ConnectionPoolDataSource dataSource, int maxConnections) Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds.MiniConnectionPoolManager
(ConnectionPoolDataSource dataSource, int maxConnections, int timeout) Constructs a MiniConnectionPoolManager object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Closes all unused pooled connections.int
Returns the number of active (open) connections of this pool.Retrieves a connection from the connection pool.
-
Constructor Details
-
MiniConnectionPoolManager
Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds.- Parameters:
dataSource
- the data source for the connections.maxConnections
- the maximum number of connections.
-
MiniConnectionPoolManager
public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections, int timeout) Constructs a MiniConnectionPoolManager object.- Parameters:
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 Details
-
dispose
Closes all unused pooled connections.- Throws:
SQLException
-
getConnection
Retrieves a connection from the connection pool. IfmaxConnections
connections are already in use, the method waits until a connection becomes available ortimeout
seconds elapsed. When the application is finished using the connection, it must close it in order to return it to the pool.- Returns:
- a new Connection object.
- Throws:
MiniConnectionPoolManager.TimeoutException
- when no connection becomes available withintimeout
seconds.SQLException
-
getActiveConnections
public int getActiveConnections()Returns the number of active (open) connections of this pool. This is the number ofConnection
objects that have been issued bygetConnection()
for whichConnection.close()
has not yet been called.- Returns:
- the number of active connections.
-