ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/datashre.htm

70 lines
7.6 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Unshareable and shareable connections</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h6><a name="datashre"></a>Unshareable and shareable connections</h6>
<p>WebSphere Application Server - Express 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.</p>
<p>You can share a shareable connection with other components within the same transaction as long as each getConnection request has the same connection properties. To enable connection sharing for data sources, the following connection properties must be the same:</p>
<ul>
<li>Java Naming and Directory Interface (JNDI) name. While not actually a connection property, this requirement simply means that you can only share connections from the same dataSource in the same server.</li>
<li>Resource authentication</li>
<li>In relational databases:
<ul>
<li>Isolation level</li>
<li>Readonly</li>
<li>Catalog</li>
<li>TypeMap</li>
</ul></li>
<li>In addition, the ConnectionSpec used to get the connection must also be the same.</li>
</ul>
<p>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 the handle is associated with. This access implies that every call to getConnection returns a connection handle solely for the requesting user. Typically, you must choose unshareable if you might do things to the connection that could result in unexpected behavior occurring to another application that is sharing the connection (for example, changing the isolation level).</p>
<p>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. But, 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 expecting sharing to take place because it is up to the run time to decide whether or not to share a particular connection.</p>
<p>For WebSphere Application Server - Express, all sharing of connections is relative to the current Unit of Work (UOW) boundary. Anyone within a specific transaction, when getting a connection from a specific connection pool, gets a handle to the same physical connection (if the sharing properties are the same).</p>
<p><strong>Factors that determine sharing</strong></p>
The listing here is not an exhaustive one. The product might or might not share connections under different circumstances.
<ul>
<li><p>Only connections acquired with the same resource reference (resource-ref), which specifies the res-sharing-scope as Shareable, are candidates for sharing. The resource-ref properties of res-sharing-scope, res-auth, and res-isolation-level help determine if it is possible to share a connection. The res-isolation-level is a WebSphere extension. <!--You define these properties in the Application Assembly Tool when you assemble your application. For more information, see <a href="../admin/help/tdat_crtresref.html">Creating or changing a resource reference</a>. <img src="help.gif" width="18" height="15" align="absbottom" alt="Go to Help documentation">--></p></li>
<li><p>You can only share connections that are requested with the same properties.</p></li>
<li><p>Connection Sharing only occurs between different component instances if they are within a transaction (container- or user-initiated transaction).</p></li>
<li><p>Connection Sharing only occurs within a sharing boundary. Current sharing boundaries include Transactions and LocalTransactionContainment (LTC) boundaries.</p></li>
<li><p>Within an LTC Scope for shareable connections, only Connection Reuse is allowed within a single component instance. Connection reuse occurs when the following actions are taken with a connection: get, use, commit/rollback, close; get, use, commit/rollback, close. Note that if you use the LTC resolution-control of ContainerAtBoundary then no start/commit is needed because that action is handled by the container.</p>
<p>The connection returned on the second get is the same connection as that returned on the first get (if the same properties are used). Because the connection use is serial, only one connection handle to the underlying physical connection is used at a time, so true connection sharing does not take place. The term &quot;reuse&quot; is more accurate. This reuse feature enables an application to issue multiple getConnection() requests from a single dataSource (connection pool) within a single phase transaction.</p></li>
<!--<li><p>Shareable connections between transactions (either container-managed transactions (CMT), bean-managed transactions (BMT), or LTC transactions) follow these caching rules:</p>
<ul>
<li><p>In general, an application is not allowed to set properties on shareable connections because a user of one connection handle might not anticipate a change made to another connection handle to the same physical connection. This limitation is part of the J2EE 1.3 standard.</p></li>
<li><p>General users of resource adapters can set the connection properties on the connection factory getConnection call by passing them in a ConnectionSpec.</p>
<p>However, the properties set on the connection during one transaction are not guaranteed to be the same when used in the next transaction. Because it is not valid to share connections outside of a sharing scope, connection handles are moved off of the physical connection with which they are currently associated when a transaction ends. That physical connection is returned to the free connection pool. Connections are cleaned before going in the free pool. The next time the handle is used, it is automatically associated with an appropriate connection. The appropriateness is based on the security login information, connection properties, and (for the JDBC API) the isolation level specified in the extended resource reference, passed in on the original request that returned the current handle. Any properties set on the connection after it was retrieved are lost.</p></li>
<li><p>For JDBC users, WebSphere Application Server provides an extension to enable you to pass the connection properties through the ConnectionSpec.</p>
<p>Use caution when setting properties and sharing connections in a local transaction scope. Ensure that other components with which the connection is shared are expecting the behavior resulting from your settings.</p></li>
</ul></li>-->
<li><p>You cannot set the IsolationLevel when using a shareable connection for the JDBC API using a relational resource adapter in a global transaction. The product provides an extension to the resource reference to enable you to specify the isolation level. If your application requires the use of multiple isolation levels, create multiple resource references and map them to the same data source or connection factory.</p></li>
</ul>
</body>
</html>