AnsweredAssumed Answered

RetryingTransactionHelper learnings

Question asked by jharrop on Jun 4, 2008
Latest reply on May 29, 2017 by iru
The key method in the above is:

public <R> R doInTransaction(RetryingTransactionCallback<R> cb, boolean readOnly, boolean requiresNew)


     * @param requiresNew       <tt>true</tt> to force a new transaction or
     *                          <tt>false</tt> to partake in any existing transaction.

The other signatures both set requiresNew=false:

    public <R> R doInTransaction(RetryingTransactionCallback<R> cb)
        return doInTransaction(cb, false, false);

    public <R> R doInTransaction(RetryingTransactionCallback<R> cb, boolean readOnly)
        return doInTransaction(cb, readOnly, false);
requiresNew is used to set the boolean isNew:

           isNew = requiresNew || txn.getStatus() == Status.STATUS_NO_TRANSACTION;
                if (isNew)

The significance of isNew is that RTH only actually retries if isNew

    // Somebody else 'owns' the transaction, so just rethrow.
                if (!isNew)
         "Someone else owns this transaction " + txn );
                    if (e instanceof RuntimeException)
                        throw (RuntimeException)e;
                        throw new AlfrescoRuntimeException(
                                "Exception from transactional callback: " + cb,

It seems to me that if you are using RTH, you'll likely want to set requiresNew parameter to true.  If you use one of the simpler method signatures, it is likely RTH won't retry your transaction (which is its raison d'etre?).