Take care of net.sf.ehcache.transaction.TransactionTimeoutException

February 15, 2012 by Michael

The net.sf.ehcache.transaction.TransactionTimeoutException is one of those unchecked RuntimeExceptions you should take care of if you use ehcache. If this exceptions occurs you must explicitly rollback the ongoing transaction, otherwise all further requests to start an ehcache transaction from within the current thread will fail with another net.sf.ehcache.transaction.TransactionException as the cache is in an inconsistent state.

I do it like so:

final TransactionController transactionController = cacheManager.getTransactionController();
try {
	// Do stuff
} catch(TransactionTimeoutException e) {
	// Rollback transaction because cache will be invalid from this point
	// Rethrow or handle e in some way

No comments yet

Post a Comment

Your email is never published nor shared. Required fields are marked *