J2EE.4.2 Requirements


This section defines the transaction support requirements for the J2EE product provider.

J2EE.4.2.1 Web Components

Servlets and JSP pages are allowed to demarcate transactions using the javax.transaction.UserTransaction interface, defined in the JTA specification. These web components are allowed to access multiple resource managers and invoke multiple enterprise beans within a single transaction. The web component assumes that the transaction is automatically propagated to the enterprise beans (subject to the enterprise bean transaction attributes, e.g., such beans must use container managed transactions) and transactional resource managers.

The J2EE platform must meet the following requirements:

  • The J2EE platform must provide an object implementing the javax.transaction.UserTransaction interface to both servlets and JSP pages. The platform must publish the UserTransaction object in the Java Naming and Directory Interface (JNDI) name space available to web components under the name java:comp/UserTransaction .

  • If a web component invokes an enterprise bean from a thread associated with a JTA transaction, the J2EE platform must propagate the transaction context with the enterprise bean invocation. Whether the target enterprise bean will be invoked in this transaction context or not is determined by the rules defined in the EJB specification.

  • If a web component accesses a transactional resource manager from a thread associated with a JTA transaction, the J2EE platform must ensure that the resource access is included as part of the JTA transaction.

  • If a web component creates a thread, the J2EE platform must ensure that the newly created thread is not associated with any JTA transaction.

The product provider is not required to support import of a transaction context by a web component from its client.

The product provider is not required to support transaction context propagation across multiple web components accessed via an HTTP request. If a web component associated with a transaction makes an HTTP request to another web component, the transaction context is not propagated to the target servlet or page. (The HTTP protocol does not support such transaction context propagation.)

However, when another web component is invoked through the RequestDispatcher interface, any active transaction context must be propagated to the called web component.

A web component may start a transaction only in its service method. A transaction that is started by a servlet or JSP page must be completed before the service method returns. That is, transactions may not span web requests from a client. Returning from the service method with an active transaction context is an error. The web container is required to detect this error and abort the transaction.

There are many subtle and complex interactions between the use of transactional resources, threads, and JDBC connections. To ensure correct operation, web components should obey the following guidelines, and the web container must support at least these usages.

  • JTA transactions should be started and completed only from the thread in which the service method is called. If the web component creates additional threads for any purpose, these threads should not attempt to start JTA transactions.

  • JDBC connections may be acquired and released by a thread other than the service method thread, but should not be shared between threads.

  • JDBC Connection objects should not be stored in static fields.

  • For web components implementing SingleThreadModel , JDBC Connection objects may be stored in class instance fields.

  • For web components not implementing SingleThreadModel , JDBC Connection objects should not be stored in class instance fields, and should be acquired and released within the same invocation of the service method.

  • Enterprise beans may be invoked from any thread used by a web component. Transaction context propagation requirements are described above and in the EJB specification.

J2EE.4.2.2 Enterprise JavaBeans Components

The J2EE product provider must implement support for transactions as defined in the EJB specification.

J2EE.4.2.3 Application Clients

The J2EE product provider is not required to provide any transaction management support for application clients.

J2EE.4.2.4 Applet Clients

The J2EE product provider is not required to provide any transactional management support for applets.

J2EE.4.2.5 Transactional JDBC Technology Support

A J2EE product must support at least a JDBC technology database as a transaction resource manager. The platform must enable transactional JDBC API access from servlets, JSP pages, and enterprise beans.

It must be possible to access the JDBC technology database from multiple application components within a single transaction. For example, a servlet may wish to start a transaction, access a database, invoke an enterprise bean that accesses the same database as part of the same transaction, and finally commit the transaction.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net