Search code examples
ehcachejtadistributed-transactionsdistributed-cachingterracotta

Distributed Ehcache working using JTA


I am trying to do some bench-marking of Distributed transaction memory using Terracotta Ehcache (Open Source). I am having some problem understanding its working with JTA. In code I have found that cache interested in a Distributed Transaction enlist itself as a resource with JTA on which JTA later executes the two phase commit.

My question is if only one cache is enlisted as a resource, how JTA will be able to update all other caches atomically in distributed settings? We are not passing other caches reference to JTA, so atomically update will not be done on them. I feel, I am missing some string here, can anyone explain how it works? I am new to J2EE too, am I missing some J2EE concept which allow automatic reference passing of other caches to JTA?


Solution

  • Ehcache, if configured that way (transactionalMode="xa" or transactionalMode="xa_strict"), can work as a full XAResource to participate in JTA transactions (global transactions), which is controlled by a Transaction Manager (from your application server or some standalone product). Ehcache itself takes care of registering at the Transaction Manager in this case. Also, as a full XAResource, multiple caches can be registered and can be part of a transaction.

    Strong, cluster-wide consistency is quite expensive (there is no free lunch). It boils down using locks and synchronous (network) operations involving waits, acknowledging etc.

    For a more detailed read, I'd suggest you to consult Ehcache docs: Transactions in Ehcache