Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Administration Guide

- Previous: Chapter 10 Configuring Message Security
- Next: Chapter 12 Configuring the HTTP Service

# Chapter 11 Transactions

By enclosing one or more steps in an indivisible unit of work, a transaction ensures data integrity and consistency. This chapter contains the following sections:

- About Transactions

- Admin Console Tasks for Transactions

# About Transactions

- What is a Transaction?

- Transactions in J2EE Technology

## What is a Transaction?

A transaction is a series of discreet actions in an application that must all complete successfully or else all the changes in each action are backed out. For example, to transfer funds from a checking account to a savings account is a transaction with the following steps:

1. Check to see if the checking account has enough money to cover the transfer.

2. If there’s enough money in the checking account debit the amount from the checking account.

3. Credit the money to the savings account.

4. Record the transfer to the checking account log.

5. Record the transfer to the savings account log.

If any of these steps fails, all changes from the preceding steps must be backed out, and the checking account and savings account must be in the same state as they were before the transaction started. This event is called a rollback. If all the steps complete successfully, the transaction is in a committed state. Transactions end in either a commit or a rollback.

See Also:

- Transactions in J2EE Technology

- Configuring Transactions

## Transactions in J2EE Technology

Transaction processing in J2EE technology involves the following five participants:

- Transaction Manager

- Application Server

- Resource Manager(s)

- Resource Adapter(s)

- User Application.

Each of these entities contribute to reliable transaction processing by implementing the different APIs and functionalities, discussed below:

- The Transaction Manager provides the services and management functions required to support transaction demarcation, transactional resource management, synchronization, and transaction context propagation.

- The Application Server provides the infrastructure required to support the application runtime environment that includes transaction state management.

- The Resource Manager (through a resource adapter) provides the application access to resources. The resource manager participates in distributed transactions by implementing a transaction resource interface used by the transaction manager to communicate transaction association, transaction completion and recovery work. An example of such a resource manager is a relational database server.

- A Resource Adapter is a system level software library that is used by the application server or client to connect to a Resource Manager. A Resource Adapter is typically specific to a Resource Manager. It is available as a library and is used within the address space of the client using it. An example of such a resource adapter is a JDBC driver.

- A Transactional User Application developed to operate in an application server environment looks up transactional data sources and, optionally, the transaction manager, using JNDI. The application may use declarative transaction attribute settings for enterprise beans or explicit programmatic transaction demarcation.

See Also:

- What is a Transaction?

- Configuring Transactions

# Admin Console Tasks for Transactions

The Application Server handles transactions based on the settings in the Admin Console.

## Configuring Transactions

This section explains how to configure transaction settings:

- To configure how the Application Server recovers from transactions

- To set a transaction timeout value

- To set the location of the transaction logs

- To set the keypoint interval

For additional information about transactions, see these sections:

- What is a Transaction?

- Transactions in J2EE Technology

### To configure how the Application Server recovers from transactions

Transactions might be incomplete either because the server crashed or a resource manager crashed. It is essential to complete these stranded transactions and recover from the failures. Application Server is designed to recover from these failures and complete the transactions upon server startup.

While performing the recovery, if some of the resources are unreachable the server restart may be delayed as it tries to recover the transactions.

When the transaction spans across servers, the server that started the transaction can contact the other servers to get the outcome of the transactions. If the other servers are unreachable, the transaction uses the Heuristic Decision field to determine the outcome.

1. In the tree component select the Configuration node.

2. Select the Transaction Service node.

3. To enable the recovery of incomplete transactions, check the Recover in the On Restart field.

4. Set the amount of time, in seconds, the Application Server tries to connect to the unreachable server in the Retry Timeout field. The default value is 10 minutes (600 seconds).

5. Set the policy for unreachable servers in a transaction in the Heuristic Decision field.

   Unless there is a good reason to set this field to Commit, leave Heuristic Decision set to Rollback. Committing indeterminate transactions can compromise the data integrity of your application.

6. Click Save.

7. Restart the Application Server.

### To set a transaction timeout value

By default, the server does not timeout a transaction. That is, the server waits indefinitely for a transaction to complete. If you set a timeout value for transactions, if a transaction isn’t completed within the configured time, the Application Server rolls back the transaction.

1. In the tree component, select the Configuration node.

2. Select the Transaction Service node.

3. Enter the number of seconds before the transaction times out, in the Transaction Timeout field.

   The default value of Transaction Timeout is 0 seconds. This disables transaction timeouts.

4. Click Save.

5. Restart the Application Server.

### To set the location of the transaction logs

The transaction log records the information about each transaction in order to maintain the data integrity of the resources involved and to recover from failures. Transaction logs are kept in the `tx` subdirectory of the directory specified by the Transaction Log Location field. These logs are not human readable.

1. In the tree component, select the Configuration node.

2. Select the Transaction Service node.

3. Enter the location of the transaction logs in the Transaction Log Location field.

   A `tx` subdirectory is created and transaction logs are kept under that directory.

4. Click Save.

5. Restart the Application Server.

### To set the keypoint interval

Keypoint operations compress the transaction log file. The keypoint interval is the number of transactions between keypoint operations on the log. Keypoint operations can reduce the size of the transaction log files. A larger number of keypoint intervals (for example, 2048) results in larger transaction log files, but fewer keypoint operations, and potentially better performance. A smaller keypoint interval (for example, 256) results in smaller log files but slightly reduced performance due to the greater frequency of keypoint operations.

1. In the tree component select the Configuration node.

2. Select the Transaction Service node.

3. Enter the number of transactions between keypoint operations in the Keypoint Interval field.

4. Click Save.

5. Restart the Application Server.

- Previous: Chapter 10 Configuring Message Security
- Next: Chapter 12 Configuring the HTTP Service

- © 2010, Oracle Corporation and/or its affiliates