We use XA/distributed transaction, and I'm trying to notify/update global transaction status, should a participating xaResource-branch throw an exception.
A good example can be found in JMS Connection#setExceptionListener()
, (ref.link), which offers notification hook in the ExceptionListener
. I'm looking for something similar in JDBC specification, but I haven't been able to find any.
XA Transaction processing is single-threaded in our application, and a given global transaction can touch multiple xaResource-branches. Assuming UOW happens in the order of rA
, rB
and rC
, it happens we might have a slow query running on rB
, causing rA
timeout before rC
starts. Because of the single threaded nature (and the limitation of the TM we use), rC
still proceeds while the fate of the global transaction has already been determined (to rollback). We are trying to notify the global transaction of the fact rA
has already been rolled back so that rC
can be skipped.
If the JDBC specification doesn't offer something similar to JMS's ExceptionListener, one option I can think of would be using async thread(s) to test the JDBC connection with a certain frequency. The closest example I've found so far is described in this PostgreSQL documentation (ref.link), which uses asynchronous thread(s) to test/poll JDBC connection. It probably satisfies my need, but wondering if there's any other option I missed in the JDBC specification.