com.jolbox.bonecp
Class CachedConnectionStrategy

java.lang.Object
  extended by com.jolbox.bonecp.AbstractConnectionStrategy
      extended by com.jolbox.bonecp.CachedConnectionStrategy
All Implemented Interfaces:
ConnectionStrategy

public class CachedConnectionStrategy
extends AbstractConnectionStrategy

A connection strategy that is optimized to store/retrieve the connection inside a thread local variable. This makes getting a connection in a managed thread environment such as Tomcat very fast but has the limitation that it only works if # of threads <= # of connections. Should it detect that this isn't the case anymore, this class will flip back permanently to the configured fallback strategy (i.e. default strategy) and makes sure that currently assigned and unused connections are taken back.

Author:
wallacew

Field Summary
 
Fields inherited from class com.jolbox.bonecp.AbstractConnectionStrategy
pool, terminationLock
 
Method Summary
protected  Connection getConnectionInternal()
          Actual call that returns a connection
static ConnectionStrategy getInstance(BoneCP pool, ConnectionStrategy fallbackStrategy)
          Singleton pattern.
 ConnectionHandle pollConnection()
          Obtains a connection using the configured strategy without blocking.
 void terminateAllConnections()
          Destroys all connections using this strategy.
 
Methods inherited from class com.jolbox.bonecp.AbstractConnectionStrategy
getConnection, postConnection, preConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConnectionStrategy getInstance(BoneCP pool,
                                             ConnectionStrategy fallbackStrategy)
Singleton pattern.

Parameters:
pool -
fallbackStrategy -
Returns:
CachedConnectionStrategy singleton instance

getConnectionInternal

protected Connection getConnectionInternal()
                                    throws SQLException
Description copied from class: AbstractConnectionStrategy
Actual call that returns a connection

Specified by:
getConnectionInternal in class AbstractConnectionStrategy
Returns:
Connection
Throws:
SQLException

pollConnection

public ConnectionHandle pollConnection()
Description copied from interface: ConnectionStrategy
Obtains a connection using the configured strategy without blocking.

Specified by:
pollConnection in interface ConnectionStrategy
Overrides:
pollConnection in class AbstractConnectionStrategy
Returns:
Connection

terminateAllConnections

public void terminateAllConnections()
Description copied from interface: ConnectionStrategy
Destroys all connections using this strategy.



Copyright © 2009-2012 JolBox. All Rights Reserved.