Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
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:
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 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.
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").
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.
You can specify a transaction timeout for an EJB 3.0 session bean using the following OC4J-proprietary annotations and their attributes:
@StatelessDeployment
attribute transactionTimeout
@StatefulDeployment
attribute transactionTimeout
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"); } }
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.
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:
J2EE Connector Architecture (J2CA) adapter message provider: you can change the transaction timeout (see "J2CA Adapter Message Service Provider").
OEMS JMS: you cannot change the transaction timeout from the default of 86,400 seconds (1 day).
OEMS JMS Database: you can change the transaction timeout (see "Non-J2CA Adapter Message Service Provider").
Configuration in the deployment XML overrides the corresponding configuration made 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) { ... } }
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.