Connection handles

A connection handle is a representation of a physical connection.

To use a back end resource (such as a relational database) in the WebSphere Application Server - Express you must 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. Get a connection.
  2. Do the work.
  3. Commit (if appropriate).
  4. Close the connection.

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

  1. Get a connection.
  2. Begin a global transaction.
  3. Do work on the connection.
  4. Commit a global transaction.
  5. Do 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.

Note: There is limited connection caching available for servlets. Connection handles can be cached only in single-threaded servlets. Caching of connection handles across servlet methods is limited to JDBC resources. Other non-relational resources, such as Customer Information Control System (CICS) or Information Management System (IMS), currently cannot have their connection handles cached in a servlet. When connection caching is not available, you must get, use, and close the connection handle within each method invocation.

You are encouraged not to cache the connection across the transaction boundary for shareable connections, the get/use/close pattern is preferred. This 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 topics.

Here are the possible benefits of unshared connections:

Here are 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 topics.

Here are the possible benefits of shared connections:

Here are the possible drawbacks of shared connections: