Home

XAResource

XAResource is an interface defined by the X/Open XA standard that enables a resource manager to participate in a distributed transaction coordinated by a transaction manager. In Java, it is exposed as javax.transaction.xa.XAResource (and jakarta.transaction.xa.XAResource in newer specifications). Resource managers such as relational databases, message queues, or other data stores implement XAResource to participate in a global transaction across multiple resources.

Core purpose and usage: XAResource provides the contract through which a resource manager coordinates with a

Key methods: The interface includes start(Xid, int flags) to associate a global transaction with the resource,

Xid and exceptions: XAResource operations use Xid, a global transaction identifier, to distinguish different transactions and

transaction
manager
to
execute
work
as
part
of
a
global
transaction.
The
transaction
manager
oversees
the
propagation
of
a
single
logical
transaction
across
multiple
resources
and
coordinates
the
overall
commit
or
rollback
via
a
two-phase
commit
protocol.
end(Xid,
int
flags)
to
end
work
on
that
transaction,
and
prepare(Xid)
to
ask
the
resource
to
prepare
for
commit.
For
finalization,
commit(Xid,
boolean
onePhase)
commits
the
transaction
(onePhase
can
be
used
to
optimize
when
a
single
resource
is
involved),
and
rollback(Xid)
aborts
it.
Additional
methods
include
recover(int
flag)
to
obtain
in-doubt
transactions,
forget(Xid)
to
release
heuristically
decided
transactions,
isSameRM(XAResource)
to
compare
resource
managers,
and
setTransactionTimeout(int
seconds)
to
configure
timeouts.
branches.
XAException
provides
error
codes
for
method
outcomes
(for
example,
outcomes
of
prepare).
This
interface
is
a
foundational
part
of
distributed
transaction
management
in
Java
EE
and
Jakarta
EE,
implemented
by
many
database
drivers,
messaging
systems,
and
other
transactional
resources.