Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

Beginning with version 0.3.1, Concourse provides a framework for creating connection pools of cached database connections to the database. Applications that use connection pools may benefit from increased performance since requests can take advantage of previously established connections and therefore avoid the overhead of establishing a new one. creating new ones.

Concourse supports both fixed and cached connection pools. A FixedConnectionPool maintains a fixed number of connections for the duration of its use. If all the connections from a fixed pool are taken, then subsequent requests will block until a connection is returned to the pool. On the other hand, a CachedConnectionPool never blocks and will create new connections on demand if the pool does not have any available to service a request.

You can create both kinds of connection pools by calling the appropriately named static factory method in the ConnectionPool class.

Code Block
languagejava
titleCreating a FixedConnectionPool
ConnectionPool connections = ConnectionPool.newFixedConnectionPool(host, port, username, password, poolSize);
Code Block
languagejava
titleCreating a CachedConnectionPool
ConnectionPool connections = ConnectionPool.newCachedConnectionPool(host, port, username, password);

Usage

Code Block
languagejava
// assumes that the connection pool has been previously created
Concourse connection = null;
try{
	connection = pool.request();
	// do stuff
}
finally {
	if(connection != null){
		pool.release(connection);
	}
}

 

API Documentation

The API for fixed and cached connection pools is the same.

close

Code Block
void close() throws Exception

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

hasAvailableConnections

Code Block
boolean hasAvailableConnections()

Return true if this pool has any available connections.

Returns

  • true if a subsequent call the request() will not block

release

Code Block
void release(Concourse connection)

Return a previously requested connection back to the pool.

Parameters

  • connection

request

Code Block
Concourse request()

Request a connection from the pool and possibly block until one is available.

Returns

  • a connection to Concourse