9 Using Batching with Message-Driven Beans
onMessage invocation. Message receipts and participating transactional work from those invocations share the same transaction. This can reduce transaction-completion overhead. Different batches can be processed concurrently.For information on transaction management within MDBs, see Configuring Transaction Management Strategy for an MDB.
Note:
Transaction batching is not effective for all MDB applications. For example, database deadlocks can occur in an application where an MDB makes multiple calls to a database. Using the transaction batching feature can cause the MDB to lock more rows per transaction which can lead to database deadlocks.
This chapter includes the following sections:
Configuring MDB Transaction Batching
Required transaction attribute for onMessage. To enable batching, set max-messages-in-transaction within the message-driven-descriptor element of weblogic-ejb-jar.xml, or set the WebLogic-specific maxMessagesInTransaction activation configuration property, to a value greater than 1. The default value, 1, processes one message per transaction.max-messages-in-transaction specifies the maximum number of messages processed in one transaction. However, increasing the batch size can increase latency. You should start with a small value, 5 for example. You can increase this value as your application performance allows.
When using MDB batching, more messages are processed per transaction. This may cause more transactions to time out since more work is being performed in each transaction. To increase the transaction timeout, set the trans-timeout-seconds element within the MDB's transaction-descriptor element under weblogic-enterprise-bean in weblogic-ejb-jar.xml. Alternatively, apply WebLogic's @TransactionTimeoutSeconds annotation to the MDB class. For example, place the following annotation directly before the existing MDB class declaration, alongside its other class annotations, to configure a 60-second timeout:
@weblogic.javaee.TransactionTimeoutSeconds(60)
An explicitly configured trans-timeout-seconds value in weblogic-ejb-jar.xml takes precedence over the annotation.
How MDB Transaction Batching Works
For each batch, the container begins a transaction and invokes onMessage separately for each message as it is received. During normal processing, it attempts to commit the transaction when the batch limit is reached or a subsequent receive returns no message. A batch can therefore contain fewer messages than the maximum specified by max-messages-in-transaction or the maxMessagesInTransaction activation configuration property. Figure 9-1 illustrates the normal receive, process and commit sequence.
Figure 9-1 MDB Transaction Batching Transaction Processing Flow

Description of "Figure 9-1 MDB Transaction Batching Transaction Processing Flow"
If processing a message causes the batch transaction to roll back, all message receipts and participating transactional work in that transaction are rolled back together. During error recovery, the container can temporarily use one message per transaction before resuming batching. This can also occur after a transaction timeout. Messages rolled back with the transaction become eligible for redelivery according to the JMS provider's redelivery configuration and policies.