Beruflich Dokumente
Kultur Dokumente
Agenda
Introduction
Trace Options for J2C
Terminology
Resource Look Up
Get Connection Request (LTC, User Tran)
Connection Pool Dump
Close Connection Request (LTC, User Tran)
Connection Leak Logic
Introduction
IBM WebSphere Application Server V6.x provides implementation and
support for the new J2EE Connector Architecture (JCA) specification v1.5 as
part of the J2EE 1.4 platform.
The JCA provides a standard mechanism that allows J2EE applications to
connect and use heterogeneous resources from
Enterprise information systems (EIS)
Relational database systems
Trace Options
WAS.j2c=all
Includes all J2C classes
ConnLeakLogic
Part of WAS.j2c
Enabled by default if WAS.j2c is enabled
Can be disabled by setting
ConnLeakLogic=off
Provides stack dump for connections that are in use more
than 10 seconds.
ConnCloseLogic
Not part of WAS.j2c
Provides stack dump for connection close requests
Must be entered manually in Trace Specification:
ConnCloseLogic=on
Terminology
J2C
WebSphere Application Servers JCA implementation
Application component
Part of an application such as a servlet or EJB, normally
running on an application server
RM (Resource Manager)
Logical front-end which manages the resources of an
EIS (Enterprise Information System) or relational
database
RA (Resource Adapter)
Provides connectivity between an application component
and RM/EIS per the contracts specified in the JCA
Terminology (Contd)
Connection
An object which provides connectivity to an EIS/Database for an
application component
Connection pooling
The pooling of connections means that Connections, when an
application is finished using them, are kept open with the RM in a
pool rather than actually being closed. A subsequent Connection
request by an application may then re-use a Connection from the pool
instead of Connections being constantly opened/closed with the
RM/EIS
Pooling provides lower latency for Connection requests during typical
usage, while the number and size of the pools serves to limit the EIS
resources that may be consumed during peak usage periods
Terminology (Contd)
ConnectionFactory
RA provides a ConnectionFactory as the interface for an
application component to request a Connection to the
EIS
A DataSource is a JDBC-specific kind of
ConnectionFactory
ConnectionManager
JCA interface which provides the hook for the RA to
delegate a Connection request to the app server
Each Resource has a unique ConnectionManager
CRI (ConnectionRequestInfo)
Contains the RAs own request-specific data
Terminology (Contd)
MCF (ManagedConnectionFactory)
RA interface for the app server to match and create ManagedConnections.
MC (ManagedConnection)
RA interface to represent an EIS Connection to the app server.
MCW (ManagedConnectionWrapper)
A wrapper object used by J2C to manage the state of MC objects.
An MCW can have the following states:
STATE_NEW initial state, before first use.
STATE_ACTIVE_FREE not allocated to any user.
STATE_ACTIVE_INUSE allocated to a user, but not currently used in a
transaction.
STATE_TRAN_WRAPPER_INUSE allocated to a user, and associated
with a transaction.
STATE_INACTIVE no longer associated with a MC or a connection pool,
the MCW is parked in a MCW pool (distinct from any connection pool) for
possible later reuse.
Terminology (Contd)
Connection Handle
Java Object returned to application when a get connection request is
executed
Is a reference to the RAs managed connection object
ConnectionEventListener
An application server interface for a ManagedConnection object to
make callbacks to the app server to report significant events in the
Connection life cycle
PoolManager
J2C object which implements a connection pool.
One PoolManager per ConnectionFactory.
A J2C connection pool can be thought of as having 3 sub-pools:
Free pool
Shareable connection pool
Unshareable connection pool
Terminology (Contd)
Shareable Connection
Sharing a connection can only happen within a sharing scope. The most
common sharing scope is a transaction scope where multiple active
connection handles can share the same physical connection
A global transaction is either a user transaction initiated by the J2EE
application, or a container global transaction initiated by the
Application Server Enterprise Java Bean (EJB) container
Local Transaction Containment (LTC) is always established by the
container in the absence of a global transaction
Allows for multiple getConnection requests by different parts of an
application to each be provided with their own reference (or handle) to the
same Managed Connection simultaneously (user tran only) or serially
(LTC)
Reduces the Connection resources required by an application
Terminology (Contd)
Several conditions must be met for a Shareable Connection
to actually be shared. If any of the following requirements is
not met, two getConnection calls will return two distinct
physical (managed) connections:
Java Naming and Directory Interface (JNDI) name
Resource authentication setting
Principal
Connection transaction isolation level property
Connection readOnly, catalog, and typeMap properties
Terminology (Contd)
Unshareable Connection
An unshareable connection is not shared with other
components in the application
The component using this connection has full control of
this connection
See Information Center Topic Unshareable and
shareable connections at URL for more information:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/co
m.ibm.websphere.nd.doc/info/ae/ae/cdat_conshrnon.html
Terminology (Contd)
Local transaction containment (LTC)
LTC is used to define the application server behavior in an unspecified
transaction context
Unspecified transaction context is defined in the Enterprise
JavaBeans 2.0 (or later) specification; for example, at
http://java.sun.com/products/ejb/2.0.html
A LTC is a bounded unit-of-work (UOW) scope, within which zero, one, or
more resource manager local transactions (RMLTs) can be accessed.
The LTC defines the boundary at which all RMLTs must be complete; any
incomplete RMLTs are resolved, according to policy, by the
Container
For more information, see Information Center section Local transaction
containment (LTC) at URL:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.w
ebsphere.base.doc/info/aes/ae/cjta_loctran.html
direct Lookup
[4/23/07 22:29:29:242 CDT] 0000001a ConnectionFac 3 resRefOrBeanName used
to create CMConfigData is: null
[4/23/07 12:08:49:316 CDT] 0000001b ConnectionFac W J2CA0294W: Deprecated
usage of direct JNDI lookup of resource jdbc/snoop. The following default
values are used:
[Resource-ref settings]
res-auth: 1 (APPLICATION) <<< Component
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
Indirect Lookup
[4/17/07 15:40:26:891 PDT] 00000026 ConnectionFac 3 resRefOrBeanName
used to create CMConfigData is: jdbc/myimsdb1
[4/17/07 15:40:26:906 PDT] 00000026 ConnectionFac 3 Using CMConfigData
values:
[Resource-ref settings]
res-auth: 0 (CONTAINER)
res-isolation-level: 4 (TRANSACTION_REPEATABLE_READ)
res-sharing-scope: true (SHAREABLE)
getConnection (LTC)
Application component calls the getConnection method on the
ConnectionFactory/DataSource instance in the RA, looked up via JNDI:
ds.getConnection();
Connection Close
When a MC is created, J2C calls addConnectionEventListener
on the MC to register a J2C Listener with the
ManagedConnection
The MC must send a ConnectionEvent to all registered listeners
to notify them when a Connection handle is closed by the
application, when an error occurs which makes the Connection
unusable, or when certain LocalTransaction events occur.
This gives J2C the information it needs to decide when to
release a connection to the Free pool, mark an MC for
cleanup/destruction, or to update transaction related state
information
ds = (javax.sql.DataSource) ctx.lookup("jdbc/snoop");
Connection con1 = null;
Connection con2 = null;
try {
con1 = ds.getConnection();
con2 = ds.getConnection();
ds = (javax.sql.DataSource) ctx.lookup("jdbc/snoop");
Connection con1 = null ;
UserTransaction ut = ctx.lookup("java:comp/UserTransaction");
ut.begin();
con1 = ds.getConnection();
No free connections
[4/23/07 22:29:30:174 CDT] 0000001a PoolManager 3 Searching for shared connection in partition 1
[4/23/07 22:29:30:174 CDT] 0000001a SharedPool > getSharedConnection Entry
[4/23/07 22:29:30:174 CDT] 0000001a SharedPool < getSharedConnection, returning mcWrapper Exit
MCWrapper id 3bebff47 Managed connection WSRdbManagedConnectionImpl@1c1e7f47
State:STATE_TRAN_WRAPPER_INUSE Thread Id: a8ebf42 Thread Name: WebContainer : 0 Handle count 1
ds = (javax.sql.DataSource) ctx.lookup("jdbc/snoop");
Connection con1 = null ;
UserTransaction ut = ctx.lookup("java:comp/UserTransaction");
ut.begin();
con1 = ds.getConnection();
con1.close;
ut.commit();
[4/23/07 22:29:30:324 CDT] 0000001a PoolManager 3 release(), Pool contents ==> PoolManager name:jdbc/snoop2
PoolManager object:940883806
Total number of connections: 1 (max/min 10/1, reap/unused/aged 180/1800/0, connectiontimeout/purge 180/EntirePool)
(testConnection/inteval false/0, stuck timer/time/threshold 0/0/0, surge time/connections 0/-1)
Shared Connection information (shared partitions 200)
com.ibm.ws.Transaction.JTA.TransactionImpl@161c3f5e#tid=1 MCWrapper id 147e7f4e Managed connection
WSRdbManagedConnectionImpl@e98ff4e State:STATE_ACTIVE_INUSE Thread Id: a8ebf42 Thread Name:
WebContainer : 0 Handle count 0
Total number of connection in shared pool: 1
No free connections
Connection Leak
A connection leak occurs when the application uses a
connection, but it never explicitly calls the close() method on
the connection object to return the connection back to the
connection pool for reuse
Connection is associated with a Transaction that is not
committed
You might have a connection leak if your application
receives exceptions such as:
com.ibm.websphere.ce.cm.ConnectionWaitTimeoutException
com.ibm.websphere.ce.j2c.ConnectionWaitTimeoutException
Enable ConnLeakLogic=all trace to gather information about
which application methods could potentially lead to leaking
connections (not closing connection) or holding on to
connections longer than expected
Reference
WebSphere Application Server V6: JCA Connection Problem Determination
http://www.redbooks.ibm.com/redpieces/pdfs/redp4080.pdf
Connection sharing
http://www.ibm.com/developerworks/websphere/library/techarticles/0404_tang/0404_tan
g.html
Connection Behavior
http://www.ibm.com/developerworks/websphere/library/techarticles/0506_johnsen/0506_
johnsen.html