+

Search Tips   |   Advanced Search

Unshareable and shareable connections


The appserver supports both unshareable and shareable connections. An unshareable connection is not shared with other components in the application. The component using this connection has full control of this connection.

Access to a resource marked as unshareable means that there is a one-to-one relationship between the connection handle a component is using and the physical connection with which the handle is associated. This access implies that every call to the getConnection method returns a connection handle solely for the requesting user. Typically, choose unshareable if we might do things to the connection that could result in unexpected behavior occurring in another application that is sharing the connection (for example, unexpectedly changing the isolation level).

Marking a resource as shareable allows for greater scalability. Instead of creating new physical connections on every getConnection() invocation, the physical connection (that is, managed connection) is shared through multiple connection handles, as long as each getConnection request has the same connection properties. However, sharing a connection means that each user must not do anything to the connection that could change its behavior and disrupt a sharing partner (for example, changing the isolation level). The user also cannot code an application that assumes sharing to take place because it is up to the run time to decide whether or not to share a particular connection.

 

Connection property requirements

To permit sharing of connections used within the same transaction, the following data source properties must be the same:

To permit sharing of connections within the same transaction, the following properties must be the same for the connection factories:

In addition, the ConnectionSpec object used to get the connection must also be the same.

JMS connections cannot be shared with non-JMS connections.

 

Sharing a connection with a CMP bean

The appserver allows you to share a physical connection among a CMP bean, a BMP bean, and a JDBC application to reduce the resource allocation or deadlock scenarios. There are several ways to ensure that all of these entity beans and the JDBC applications are sharing the same physical connection.

 

Factors that determine sharing

The listing here is not an exhaustive one. WAS ND v7.0 might or might not share connections under different circumstances.

 

Maximal connection sharing

To maximize connection sharing opportunities for an application, ensure that each component has the local transaction containment (LTC) Resolver attribute set to ContainerAtBoundary. This setting specifies that the component container, rather than the application code, resolves all resource manager local transactions (RMLTs) within the LTC scope. The container begins an RMLT when a connection is first used within the LTC scope, and completes it automatically at the end of the LTC scope.

See the topic, Set transactional deployment attributes, for instructions on setting the transaction resolution control and other attributes.

 

Connection sharing violations

There is a new exception, the sharing violation exception, that the resource adapter can issue whenever an operation violates sharing requirements. Possible violations include changing connection attributes, security settings, or isolation levels, among others. When such a mutable operation is performed against a managed connection, the sharing violation exception can occur when both of the following conditions are true:

Both the component and the J2C run time might need to detect this sharing violation exception, depending on when and how the managed connection becomes unshareable. If the managed connection becomes unshareable because of an operation through the connection handle (for example, you change the isolation level), then the component needs to process the exception. If the managed connection becomes unshareable without being recognized by the application server (due to some component interaction with the connection handle), then the resource adapter can reject the creation of a connection handle by issuing the sharing violation exception.



Related concepts


Relational resource adapters and JCA
Data sources
Connection pooling
Connection handles
Requirements for setting isolation level

 

Related tasks


Set transactional deployment attributes
Use the transaction service

 

Related


Extensions to data access APIs
Connection considerations when migrating servlets, JSPs, or enterprise session beans
Access intent and isolation level
Access intent policies