Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring Transaction Timeouts

To improve application performance, you can configure a transaction timeout that determines how long OC4J will wait for a transaction to commit or rollback.

This section describes the following:

Configuring a Global Transaction Timeout

You can set a transaction timeout that applies globally to all transactions that OC4J manages for session and entity beans.

You can configure the global transaction timeout as follows:

Using Application Server Control Console

Using the Application Server Control Console (see "Using Oracle Enterprise Manager 10g Application Server Control"), you can set the JTAResource MBean attribute transactionTimeout.

For more information, see "How to configure the OC4J Transaction Manager" in the Oracle Containers for J2EE Services Guide.

Using Deployment XML

In the <OC4J_HOME>\j2ee\home\config\transaction-manager.xml file you set the global transaction timeout with the transaction-timeout attribute of the <transaction-manager> element.

For example, if you wanted to set the global transaction timeout to 180 seconds, you would do as follows:

<transaction-manager ...  transaction-timeout="180"
  ...
</transaction-manager>

If you change this property using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to modify this parameter dynamically without restarting OC4J (see "Using Application Server Control Console").

Configuring a Transaction Timeout for a Session Bean

You can specify a transaction timeout for each session bean using OC4J-proprietary annotations (see "Using Annotations"), or using the orion-ejb-jar.xml file (see "Using Deployment XML").

The session bean transaction timeout overrides the global transaction timeout (see "Configuring a Global Transaction Timeout").

Configuration in the deployment XML overrides the corresponding configuration made using annotations.

Using Annotations

You can specify a transaction timeout for an EJB 3.0 session bean using the following OC4J-proprietary annotations and their attributes:

For more information on these attributes, see Table A-1.

Example 21-5 shows how to configure these attributes for an EJB 3.0 stateless session bean using the @StatelessDeployment annotation.

Example 21-5 @StatelessDeployment transactionTimeout Attribute

import javax.ejb.Stateless;
import oracle.j2ee.ejb.StatelessDeployment;

@Stateless
@StatelessDeployment(transactionTimeout=10)
public class HelloWorldBean implements HelloWorld {
    public void sayHello(String name) {
        System.out.println("Hello " + name + " from first EJB3.0");
    }
}

Using Deployment XML

In the orion-ejb-jar.xml file you set a session bean transaction timeout with the transaction-timeout attribute of the <session-deployment> element.

For example, if you wanted to set the global transaction timeout to 180 seconds, you would do as follows:

<session-deployment ...  transaction-timeout="180"
  ...
</session-deployment>

If you change this property using this method, you must restart OC4J to apply your changes.

Configuring a Transaction Timeout for a Message-Driven Bean

You can configure a transaction timeout for a message-driven bean using OC4J-proprietary annotations (see "Using Annotations") or using the orion-ejb-jar.xml file (see "Using Deployment XML").

Because the global transaction timeout (see "Configuring a Global Transaction Timeout") does not apply to message-driven beans, you must configure transaction timeout for each message-driven bean if you want to change the default transaction timeout for a message-driven bean.

The type of message service provider you use (see "What Message Service Providers Can you use With Your MDB?") affects your transaction timeout options in the following way:

Configuration in the deployment XML overrides the corresponding configuration made using annotations.

Using Annotations

You can specify a transaction timeout for an EJB 3.0 session bean using the OC4J-proprietary annotation @MessageDrivenDeployment attribute transactionTimeout.

For more information on this attribute, see Table A-3.

Example 21-5 shows how to configure this attribute for an EJB 3.0 message-driven bean using the @MessageDrivenDeployment annotation.

Example 21-6 @MessageDrivenDeployment

import javax.ejb.MessageDriven;
import oracle.j2ee.ejb.MessageDrivenDeployment;
import javax.ejb.ActivationConfigProperty;
import javax.annotation.Resource;

@MessageDriven(
    activationConfig = {
        @ActivationConfigProperty(
            propertyName="messageListenerInterface",
            propertyValue="javax.jms.MessageListener"),
        @ActivationConfigProperty(
            propertyName="connectionFactoryJndiName",
            propertyValue="jms/TopicConnectionFactory"),
         @ActivationConfigProperty(
            propertyName="destinationName", 
            propertyValue="jms/demoTopic"),
         @ActivationConfigProperty(
            propertyName="destinationType",
            propertyValue="javax.jms.Topic"),
         @ActivationConfigProperty(
            propertyName="messageSelector", 
            propertyValue="RECIPIENT = 'MDB'")
    }
)
@MessageDrivenDeployment(transactionTimeout=10)
public class MessageLogger implements MessageListener, TimedObject {
    @Resource javax.ejb.MessageDrivenContext mc;

    public void onMessage(Message message) {
    ...
    }

    public void ejbTimeout(Timer timer) {
    ...
    }
}

Using Deployment XML

You set the transaction timeout in the orion-ejb-jar.xml file. How you configure this value depends on the type of message-service provider you are using:

Non-J2CA Adapter Message Service Provider

If you are using a non-J2CA adapter message service provider like OEMS JMS or OEMS JMS Database, use the transaction-timeout attribute of the <message-driven-deployment> element.

For example, if you are using OEMS JMS or OEMS JMS Database, and you wanted to set the transaction timeout to 180 seconds, you would do as follows:

<message-driven-deployment ...  transaction-timeout="180"
  ...
</message-driven-deployment>

J2CA Adapter Message Service Provider

If you are using a J2CA adapter message service provider, use the <config-property> element to set the transactionTimeout configuration property.

For example, if you are using a J2CA adapter message service provider, and you wanted to set the transaction timeout to 180 seconds, you would do as follows:

<message-driven-deployment ... >
...
    <config-property>
        <config-property-name>transactionTimeout</config-property-name>
        <config-property-value>180</config-property-value>
    </config-property>
...
</message-driven-deployment>

In either case, if you change this property using this method, you must restart OC4J to apply your changes.