---
schema_version: "1"
id: 39807273dde0d22a3a82853a2697bab1c2c0ba0f5ed97f03574f060feeed6236
title: Using Bitronix to Manage Transactions
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.6/using-bitronix-to-manage-transactions.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.6/using-bitronix-to-manage-transactions
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0272dfd75d8996e062f112452d800d261dfd633637f53a1152a9f3930733e89a
description: MuleSoft Documentation Site
release: "4.6"
latest: false
---
---
product: Mule Runtime
version: 4.6
keywords: bitronix, transaction, xa, management, bti
---

# Using Bitronix to Manage Transactions

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Bitronix Transaction Manager allows Mule to automatically recover interrupted transactions on
restart.

If a Mule instance crashes or loses connectivity to a resource manager (such as a JMS broker,
database, etc.), this can cause a transaction to fail abnormally between the prepare phase and the
commit phase of the two-phase commit protocol (2PC). In this case, the transaction manager needs to
run a recovery process to complete any in-flight transaction that was taking place during the
failure. While this kind of failure is unlikely, a mechanism is needed to retain data consistency
when this happens.

## Using Bitronix in a Single Application

To configure an application to use Bitronix, declare the transaction manager outside of your flows,
as shown below.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
      xsi:schemaLocation="
       http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
       http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd">
    <bti:transaction-manager/>
...
</mule>
```

## Using Bitronix in All Applications in a Mule Domain

To use Bitronix in all applications associated with a Mule domain, define Bitronix as the
transaction manager in your domain configuration file, as shown below. Doing so causes all
applications associated with the domain to use Bitronix, without needing to declare the transaction
manager in individual applications.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<domain:mule-domain
        xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:domain="http://www.mulesoft.org/schema/mule/ee/domain"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/ee/domain http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd
http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd">
	<bti:transaction-manager/>

    <!-- ... -->

</domain:mule-domain>
```

See [Shared Resources](https://docs.mulesoft.com/mule-runtime/4.6/shared-resources) for information about domains.

## Adding Bitronix from Anypoint Studio

You can add Bitronix to your application or domain from Studio, by following these steps:

1.  Go to the **Global Elements** tab.

2.  Click on **Create** button.

3.  Search for `Bitronix Transaction Manager`.

    ![bitronix-studio](/mulesoft/current/en-us/mule-runtime/4.6/_images/bitronix-studio.png)

## Configuring the Bitronix Transaction Manager

The default configuration values for Bitronix are suitable for most use cases. However, if you wish
to customize the transaction manager, you can do so by using system properties or the `wrapper.conf`
file located in the `$MULE_HOME/conf` directory.

The table below lists configuration attributes for Bitronix.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Configuration Attribute</th><th>Description</th><th>Default value</th></tr></thead><tbody><tr><td><p><code>mule.bitronix.transactiontimeout</code></p></td><td><p>Timeout for XA transactions, in seconds.</p></td><td><p>60</p></td></tr><tr><td><p><code>mule.bitronix.recoveryinterval</code></p></td><td><p>Recovery execution interval for XA transactions, in seconds.</p></td><td><p>60</p></td></tr><tr><td><p><code>mule.bitronix.serverId</code></p></td><td><p>Unique ID for the transaction manager to register in the XA transaction logs. This value must be unique for each Mule instance.</p></td><td><p>Combination of the host IP and, if running in HA, the cluster node ID.</p></td></tr></tbody></table>

### Configuring a Pooling Data Source for Databases

Bitronix integration provides a data source connection pool for the Database connector, which you
must use whenever you want to implement resource pooling in the Database connector.

You can configure a shared Pooling Data Source for all connections. This improves connection
utilization when those data sources are not heavily used by applications.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule-domain xmlns="http://www.mulesoft.org/schema/mule/ee/domain"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:db="http://www.mulesoft.org/schema/mule/db"
      xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
      xmlns:spring="http://www.mulesoft.org/schema/mule/spring"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd
               http://www.mulesoft.org/schema/mule/ee/domain http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd
               http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">

    <spring:config name="springConfig" files="domain-config/datasource-beans.xml"/>

    <bti:transaction-manager/>

    <bti:xa-data-source-pool name="pooledDataSource" dataSource-ref="jdbcDataSource"/>

    <db:generic-config name="dbConfig" dataSource-ref="pooledDataSource"/>

</mule-domain>
```

The table below lists configuration attributes for Pooling Data Source.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Required</th><th>Default value</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Identifies the pool so that the connector can reference it.</p></td><td><p>Yes</p></td><td></td></tr><tr><td><p><code>datasource-ref</code></p></td><td><p>Reference to the JDBC data source object. An <code>XADataSource</code> object must be provided.</p></td><td><p>Yes</p></td><td></td></tr><tr><td><p><code>minPoolSize</code></p></td><td><p>Defines the minimal amount of connections that can be in the pool.</p></td><td><p>No</p></td><td><p>4</p></td></tr><tr><td><p><code>maxPoolSize</code></p></td><td><p>Defines the maximum amount of connections that can be in the pool.</p></td><td><p>No</p></td><td><p>16</p></td></tr><tr><td><p><code>maxIdleTime</code></p></td><td><p>Defines the number of seconds an idle connection can stay in the pool before it is closed.</p></td><td><p>No</p></td><td><p>60</p></td></tr><tr><td><p><code>acquireIncrement</code></p></td><td><p>Determines how many connections at a time will try to acquire when the pool is exhausted.</p></td><td><p>No</p></td><td><p>1</p></td></tr><tr><td><p><code>acquireTimeoutSeconds</code></p></td><td><p>The number of seconds a client calling <code>getConnection()</code> will wait for a Connection to be checked-in or acquired when the pool is exhausted. Zero means wait indefinitely.</p></td><td><p>No</p></td><td><p>30</p></td></tr><tr><td><p><code>preparedStatementCacheSize</code></p></td><td><p>Determines how many statements are cached per pooled connection. 0 means caching is disabled.</p></td><td><p>No</p></td><td><p>5</p></td></tr></tbody></table>

## Transaction Recovery

Mule includes a transaction recovery procedure that is executed automatically, no configuration is
needed. When Mule restarts after a system crash, it connects to all of the resources involved in XA
transactions and starts the transaction recovery process, leaving all systems in a consistent state.

## See Also

- [Shared Resources](https://docs.mulesoft.com/mule-runtime/4.6/shared-resources)

- [Transaction Management](https://docs.mulesoft.com/mule-runtime/4.6/transaction-management)

- [XA Transactions](https://docs.mulesoft.com/mule-runtime/4.6/xa-transactions)
