You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
애플리케이션에서 거는 락이 아니라 DB에서 제공하는 락을 사용 (ex. SELECT * ... FOR UPDATE)
데이터 수정 시에 바로 충돌을 알 수 있다. 그렇기 때문에 낙관적 락처럼 커밋 시점에 알아채는 것에 비해 충돌에 대한 손실이 적다.
충돌이 많이 발생하는 경우에 적합하고 발생하지 않는 곳에 건다면 Lock으로 인해 그만큼 오버헤드만 발생하게 된다.
JPA에서 사용하는 방법
publicinterfaceUserRepositoryextendsJpaRepository<User, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("select * from user where id = :id ")
UserfindByIdForUpdate(longid);
}