Connection handles

 


Overview

A connection handle is a representation of a physical connection.

To use a backend resource (such as a relational database) in the WAS get a connection to that resource. When you call the getConnection() method, you get a connection handle returned. The handle is not the physical connection. The physical connection is managed by the connection manager.

There are two significant configurations or usage patterns that affect how connection handles are used and how they behave. The first is the res-sharing-scope, which is defined by the resource-reference used to look up the DataSource or Connection Factory. This property tells the connection manager whether or not you can share this connection.

The second factor that affects connection handle behavior is the usage pattern. There are essentially two usage patterns. The first is called the get/use/close pattern. This usage pattern is where an application, within a single method and without calling another method that might get a connection from the same data source or connection factory...

  1. gets a connection
  2. does its work
  3. commits (if appropriate)
  4. closes the connection.

The second usage pattern is called the cached handle pattern. This is where an application:

  1. gets a connection
  2. begins a global transaction
  3. does work on the connection
  4. commits a global transaction
  5. does work on the connection again

A cached handle is a connection handle that is held across transaction and method boundaries by an application. Cached handle support requires some additional connection handle management across these boundaries, which can impact performance. For example, in a JDBC application, Statements, PreparedStatements, and ResultSets are closed implicitly after a transaction ends, but the connection remains valid.

You are encouraged not to cache the connection across the transaction boundary for shareable connections, the get/use/close pattern is preferred. The following code segment shows the cached connection pattern.

Connection conn = ds.getConnection();
     ut.begin();
     conn.prepareStatement("....."); --> Connection runs in global transaction mode
     ...
     ut.commit();
     conn.prepareStatement(".....");   ---> Connection still valid but runs in autoCommit(True);
     ...

 


Unshareable connections

Some characteristics of connection handles retrieved with a res-sharing-scope of unshareable are described in the following sections.

 

The possible benefits of unshared connections

 

The possible drawbacks of unshared connections

 

Shareable connections

Some characteristics of connection handles retrieved with a res-sharing-scope of shareable are described in the following sections.

 

The possible benefits of shared connections

 

The possible drawbacks of shared connections