Tag: optimistic locking

Spring乐观锁定:如何重试事务方法直到提交成功

我使用Spring 2.5和Hibernate JPA实现Java和“容器”管理事务。 我有一个“后用户提交”方法,它在后台更新数据,无论ConcurrencyFailureException还是StaleObjectStateExceptionexception都需要提交,因为它永远不会显示给客户端。 换句话说,需要将乐观锁定变为悲观。 (如果方法执行需要更长的时间并且有人在其他事务中更改了数据,则可能发生) 我读了很多关于幂等的东西,如果exception搜索DEFAULT_MAX_RETRIES或6.2.7则重试。 示例或第14.5章。 重试 。 我也在这里和这里找到了stackoverflow。 我试过这个: public aspect RetryOnConcurrencyExceptionAspect { private static final int DEFAULT_MAX_RETRIES = 20; private int maxRetries = DEFAULT_MAX_RETRIES; Object around(): execution( * * (..) ) && @annotation(RetryOnConcurrencyException) && @annotation(Transactional) { int numAttempts = 0; RuntimeException failureException = null; do { numAttempts++; try { return proceed(); […]