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
Nested ClassesModifier and TypeClassDescriptionstatic classThrown ingetConnection()when no free connection becomes available withintimeoutseconds. -
Constructor Summary
ConstructorsConstructorDescriptionMiniConnectionPoolManager(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 TypeMethodDescriptionvoiddispose()Closes all unused pooled connections.intReturns 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. IfmaxConnectionsconnections are already in use, the method waits until a connection becomes available ortimeoutseconds 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 withintimeoutseconds.SQLException
-
getActiveConnections
public int getActiveConnections()Returns the number of active (open) connections of this pool. This is the number ofConnectionobjects that have been issued bygetConnection()for whichConnection.close()has not yet been called.- Returns:
- the number of active connections.
-