0

In Spring retry's README, they mention how a "stateless retry" is not enough to rollback a transaction, but a stateful retry can by using a Map ?

I don't really understand what they mean.

If I want a transactional method to rollback the transaction and retry with a new one, how is a stateful retry different than a stateless retry ?

negimaster
  • 65
  • 1
  • 4

1 Answers1

1

In order for the transaction to roll back, the exception must be propagated to the caller (assuming the transaction is started somewhere upstream of the retryable method).

With stateless, the retries are performed within the scope of a single transaction.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I read a bit more about stateless / stateful retries in Spring retry. And I think that my confusion was due to thinking that they were used the same way in the calling code. If I understood correctly, stateless retries does the retry for you whereas with stateful retries, you have to explicitely call the Retryable method several times until it stops throwing – negimaster Jan 10 '23 at 21:13
  • Yes, with stateful, the caller has to retry the calls and the framework will retrieve the state (retry count etc); whether the exception is thrown on the final retry (optionally wrapped in a `ExhaustedRetryException`) depends on configuration. – Gary Russell Jan 10 '23 at 21:19