Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

JDBC pools configuration

BTM XA datasources can be created via some java code or via a BTM-specific tool called the Resource Loader. You are free to choose the method you prefer, there is absolutely no difference between them.

Contents

Table of Contents
maxLevel3
minLevel2

Using the BTM API

BTM comes bundled with a JDBC XA connection pool which is very easy to configure. You basically have to create an instance of bitronix.tm.resource.jdbc.PoolingDataSource set some properties and you're done.

...

Tip
titleNo XADataSource implementation ?

If your database vendor does not provide a XADataSource implementation, you should have a look at the Last Resource Commit optimization.

Minimal settings

You do not have to set properties that have a default value. Here is a simplified version of the previous code creating a PoolingDataSource with minimal settings:

...

This will create a PoolingDataSource that will work exactly the same as the previous one. The only difference is that unspecified properties have been left untouched with their default value.

Eager initialization

The connection pool will be initialized during the first call to getConnection(). It might be desirable to initialize the pool eagerly, like during application startup rather than having to wait for the first requests. This can be done by calling init():

...

Note
titleInitialization must happen before TM startup

Please remember that connection pools should always be initialized before BTM starts up, ie: before calling TransactionManagerServices.getTransactionManager() as during initialization, the connection pool will register itself to the transaction manager as recoverable resource.

If you do not follow this rule, BTM might not be able to fully recover XA transactions pending finalization because not all resources are available for startup recovery.

To circumvent this problem, BTM will run a full recovery each time a new connection pool is registered after it started up. You should not rely on this as pending XA transactions might still hold locks on registered connection pools that could block new transactions.

If this is problematic for you, please let us know by voting for BTM-4.

Using the Resource Loader

A datasource configuration utility is also bundled with BTM. It is convenient to use it rather than create your datasources in code. Refer to the Resource Loader page for more details.

...