Transaction transaction = null;
try {
// setup the transaction state
TransactionHandle handle =
transactionCoordinator.createTransaction(unbounded);
transaction = handle.getTransaction();
ContextResolver.setCurrentTransaction(transaction);
try {
// notify the profiler and access coordinator
profileCollectorHandle.noteTransactional(
transaction.getId());
accessCoordinator.
notifyNewTransaction(transaction,
task.getStartTime(),
task.getTryCount());
// run the task in the new transactional context
task.getTask().run();
} finally {
// regardless of the outcome, always clear the current
// transaction state before proceeding...
ContextResolver.clearCurrentTransaction(transaction);
}
// try to commit the transaction...note that there's the
// chance that the application code masked the orginal
// cause of a failure, so we'll check for that first,
// re-throwing the root cause in that case
if (transaction.isAborted()) {
throw transaction.getAbortCause();
}
handle.commit();
// the task completed successfully, so we're done
profileCollectorHandle.finishTask(task.getTryCount());
task.setDone(null);
return true;