3.6.3 About Asynchronous Calls to Participant Apps
The MicroTx Distributed Transactions library supports asynchronous calls from an XA transaction initiator application to participant applications. This improves performance when the initiator must call multiple participant services, because the calls can run concurrently instead of sequentially.
This feature is available for Helidon and Spring Boot applications that participate in XA transactions.
How it works
MicroTx stores XA transaction context in thread-local state. When an application uses ExecutorService, FutureTask, CompletableFuture, Spring @Async, or another asynchronous execution mechanism, the new worker thread does not automatically inherit the caller thread’s MicroTx transaction context.
To use asynchronous XA calls, the application must use the MicroTx-provided async context propagation support:
- For Spring Boot, configure the async executor with
MicroTxXAContextTaskDecorator. - For Helidon, use
MicroTxXATaskExecutoror an equivalent executor that propagates the MicroTx XA context.
The initiator must wait for all asynchronous participant calls to finish before calling commit or rollback. If any asynchronous participant call fails, the initiator must roll back the XA transaction
Participant limit
MicroTx does not define a fixed hard limit on the number of participants that can be called asynchronously.
The practical limit depends on:
- Executor thread-pool size
- HTTP client connection-pool size
- Participant service capacity
- Resource manager capacity
- Transaction coordinator capacity
- Transaction timeout- CPU, memory, and network resources
Configure the executor and connection pools based on the expected number of participants and concurrent transactions.
Supported use cases
MicroTx supports asynchronous calls to participant services in the following XA use cases:
- The transaction initiator calls multiple participant applications concurrently.
- The transaction initiator propagates the same XA transaction context to each asynchronous call.
- Each participant enlists correctly with the MicroTx coordinator.
- The initiator waits for all participant calls to complete before commit or rollback.
- The initiator application does not perform concurrent asynchronous work on the same local XA resource context.
- The transaction promotion feature is not enabled.
This applies to both pure initiator applications and initiator-as-participant applications, provided the initiator-side XA work is not performed concurrently with participant calls in a way that reuses the same XA connection or resource context unsafely.
Unsupported or restricted use cases
MicroTx does not support, or does not reliably support, asynchronous XA participant calls in the following cases:
- Transaction promotion is enabled, where a local transaction is promoted to a distributed XA transaction.
- The initiator application uses multiple local resource managers while also making asynchronous participant calls.
- Multiple asynchronous threads use the same XA connection, same XA branch, or same resource manager context concurrently.
- The initiator commits or rolls back before all asynchronous participant calls have completed.
- The transaction includes non-XA participants or last-resource optimization participants.
- A common resource manager is shared by multiple async branches unless the resource manager, JDBC driver, and application access pattern explicitly support that concurrent XA usage.
Implementation references
You can use the following files as a reference while integrating the MicroTx libraries with your application.
TransferResourceAsync.java: a sample transaction initiator application, which uses the MicroTx Distributed Transactions library to make asynchronous calls to participant applications in an XA transaction. See theteller-as-participantfolder which is located in themicrotx-samplesGitHub repository.TransferResourceWithSpringAsync.java: Spring Boot initiator using Spring @Async. See theteller-as-participant-springfolder which is located in themicrotx-samplesGitHub repository.TransferResourceWithFutureTaskAsync.java: Spring Boot initiator using FutureTask and ExecutorService. See theteller-as-participant-springfolder which is located in themicrotx-samplesGitHub repository.
Parent topic: Manage XA Transactions