Configuring the Transaction Subsystem
Prev | Chapter 3. Transaction Basics | Next

## Configuring the Transaction Subsystem

When you configure your transaction subsystem, you need to consider your transaction timeout value. This value represents the longest period of time a transaction can be active. Note, however, that transaction timeouts are checked only when JE examines its lock tables for blocked locks (see Locks, Blocks, and Deadlocks for more information). Therefore, a transaction's timeout can have expired, but the application will not be notified until JE has a reason to examine its lock tables.

Be aware that some transactions may be inappropriately timed out before the transaction has a chance to complete. You should therefore use this mechanism only if you know your application might have unacceptably long transactions and you want to make sure your application will not stall during their execution. (This might happen if, for example, your transaction blocks or requests too much data.)

Note that by default transaction timeouts are set to 0 seconds, which means that they never time out.

To set the maximum timeout value for your transactions, use the `EnvironmentConfig.setTxnTimeout()` method. This method configures the entire environment; not just the handle used to set the configuration. Further, this value may be set at any time during the application's lifetime.

This value can also be set using the `je.txn.timeout` property in your JE properties file.

For example:

    package je.txn;

    import com.sleepycat.je.Environment;
    import com.sleepycat.je.EnvironmentConfig;

    import java.io.File;

    ...

    Environment myEnv = null;
    try {
        EnvironmentConfig myEnvConfig = new EnvironmentConfig();
        myEnvConfig.setTransactional(true);

        // Configure a maximum transaction timeout of 1 second.
        myEnvConfig.setTxnTimeout(1000000);

        myEnv = new Environment(new File("/my/env/home"),
                                  myEnvConfig);

        // From here, you open your databases, proceed with your
        // database operations, and respond to deadlocks as
        // is normal (omitted for brevity).

        ...

Prev | Up | Next
Secondary Indices with Transaction Applications | Home | Chapter 4. Concurrency