public class ConnectionPool
extends java.lang.Object
Connection objects are time and resource consuming to create and should be reused as much as possible. This implementation keeps and provides instances of Connection to be reused.
Constructor and Description |
---|
ConnectionPool()
Create a ConnectionPool with default parameters.
|
ConnectionPool(int maxIdleConnections,
long keepAliveDuration,
java.util.concurrent.TimeUnit timeUnit)
Create an instance of ConnectionPool with your own parameters
|
Modifier and Type | Method and Description |
---|---|
int |
connectionCount()
Returns the number of connections in the pool
|
void |
evictAll()
Close and remove all idle connections in the pool.
|
int |
maxIdleConnections()
Returns the maximum amount of idle connections the pool can keep
|
public ConnectionPool()
By default the pool will be created with 5 maximum idle connections and it will keep idle connections alive for 5 minutes before disposing of them.
public ConnectionPool(int maxIdleConnections, long keepAliveDuration, java.util.concurrent.TimeUnit timeUnit)
maxIdleConnections
- The maximum number of idle connections the pool should keep.
When the pool has this number of connections any more idle connections will be discarded.keepAliveDuration
- The amount of time the pool should keep the connections alive if they are idling.timeUnit
- The unit of time in which you provided the time duration parameter.java.lang.IllegalArgumentException
- on less than 0 for number arguments and on null for the TimeUnit argumentpublic int maxIdleConnections()
public int connectionCount()
public void evictAll()