Skip to content

Commit

Permalink
如果乐观锁锁定失败则重试 UserApplication 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Jan 7, 2025
1 parent 1e7caac commit a4f06ee
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

import java.time.OffsetDateTime;
Expand Down Expand Up @@ -118,7 +121,8 @@ public UserApplication editUserApplicationComment(Long id, String comment) throw
}

@Transactional(Transactional.TxType.NOT_SUPPORTED)
@Lock(value = LockModeType.PESSIMISTIC_WRITE)
@Lock(value = LockModeType.OPTIMISTIC)
@Retryable(retryFor = OptimisticLockingFailureException.class, backoff = @Backoff(delay = 100, multiplier = 2))
public void updateUserApplicationLastAccessTime(UserApplication userApplication) {
userApplication.setLastAccessAt(OffsetDateTime.now());
try {
Expand Down

0 comments on commit a4f06ee

Please sign in to comment.