DevPortal

How do I Manage Transactions?


Table of Contents

How do I Manage Transactions?

A J2EE-based application server supports certain infrastructural services like Naming, Transactions, Security, etc. Components that are deployed on the server use these services for activities that are detached from the business logic. The Transactions service provides transactional support to application components that are deployed on the server. The Transaction service implemented on Pramati Server is based on the Java Transaction API (JTA) 1.0.1 specification.

A transaction can be defined as a unit of work containing multiple actions that take place to complete a business process. The J2EE transaction service allows multiple method calls that make up a single transaction unit.

What are the States of Transactions?

When you complete a transaction, it can either be committed or rolled back. A transaction is committed only when all the units of the transaction are successfully completed. The data resource is updated to reflected the changes. However, if there is a failure even in one of the units in the transaction, the transaction is rolled back.

What are the Types of Transactions?

There are two types of transactions - Bean managed and Container managed. In a bean managed transaction, a bean developer needs to explicitly mark the boundaries of the transaction in the code.

For a container managed transaction, the container initiates and manages the transaction. The container marks the boundaries of a transaction. When you deploy a bean, you specify the transaction usage by declaring transaction attributes.

What are the Various Transaction Attributes?

Transaction attributes are associated with a component to determine the behavior of a transaction that is container managed. These can be set at the individual method level in the deployment descriptor file associated with the component.

Note: You can use an asterisk ‘*’ for mentioning all the methods together.

Specify the required attribute as a value to the trans-attribute tag in the deployment descriptor file, ejb-jar.xml. The various transaction attributes are:

Table 1: Transaction attributes in ejb-jar.xml

AttributeA component with this attribute
RequiredNeeds to be a part of a transaction. If a transaction is currently running, the method becomes a part of this transaction.
RequiresNewInitiates a new transaction. Any transaction that is currently running is suspended and resumed only after this method is executed.
NotSupportedDoes not require a transaction. Any transaction that is currently running is suspended and is resumed only after this component is executed.
SupportsSupports the transactional behavior of the client. If the client is running within a transaction, the component executes in the transaction. However, if the client is not associated with a transaction, the component does not start a new transaction. Essentially, the component reflects the transactional behavior of the client.
MandatoryMust be called from the client's transaction context. If not, the container will throw a javax.transaction.TransactionRequiredException.
NeverMust never be called from a client's transaction context. If not, the container will throw a java.rmi.RemoteException.

How do I Set Transaction Timeout?

To prevent bottlenecks when multiple transactions are running, you can specify the duration for which a transaction can run. After this time, a transaction timeout occurs and the transaction rolls back.

Note: Make sure that this value takes into account your system environment and business logic, otherwise, the transactions may stop before completion.

To specify the duration after which a transaction rollback occurs:

  1. Start and login to the Server. The Console Home page appears.
  2. Select Configure > Transactions in the Explore panel. The Transaction page appears.
  3. Specify the time duration (TimeOut) after which the transaction stops. This value is in seconds.
  4. Click Save.

All running transactions stop after this specified time and the transaction is rolled back.

How do I Monitor Transactions?

You can monitor the status and number of transactions by viewing the transaction statistics both at the transaction service level and the individual application level. The status indicates the reason why a transaction is not committed.

To see transactions related statistics on the Console, select Monitor > Transactions in the Explore panel. This displays the following information:

Table 2: Transaction Statistics

FieldsOptionsDescription
Total-Displays the total number of transactions that took place.
Concurrent-Displays the total number of transactions allowed.
-CurrentRefers to the current number of transactions allowed.
-MinRefers to the minimum number of transactions allowed.
-MaxRefers to the maximum number of transactions allowed.
-AvgRefers to the average number of transactions allowed.
Committed-Displays the time taken for a transaction to commit.
-CountRefers to the number of transactions committed.
RolledBack-Displays the number of transactions that have to be RolledBack.
-CountRefers to the number of RolledBack transactions.


© Pramati Technologies 2007 Runs on Pramati Server | Feedback | Legal