강의

멘토링

커뮤니티

Inflearn Community Q&A

issiscv462218's profile image
issiscv462218

asked

How to solve simultaneity issues through inventory system

Propagation.REQUIRES_NEW 를 사용하는 이유가 무엇인가요?

Written on

·

1.3K

2

안녕하세요! 선생님.

다른 락에서는 트랜잭션에 Propagation.REQUIRES_NEW 를 사용하지 않았는데 namedLock 에서는 왜 사용하나요?

javaspring동시성

Answer 3

4

안녕하세요.

부모의 트랜잭션과 동일한 범위로 묶인다면 Synchronized 와 같은 문제가 발생합니다.

Database 에 commit 되기전에 락이 풀리는 현상이 발생합니다.

그렇기때문에 별도의 트랜잭션으로 분리를 해주어 Database 에 정상적으로 commit 이 된 이후에 락을 해제하는것을 의도하였습니다.

핵심은 lock 을 해제하기전에 Database 에 commit 이 되도록 하는것입니다.

감사합니다.

0

Named locks are used to synchronize access to specific resources in a multi-threaded or distributed environment. In Spring, you can use the @Lock annotation to apply locks on methods or class-level house of hazards, and you can also specify the propagation behavior of the lock by using the @Transactional annotation.

 

0

issiscv462218님의 프로필 이미지
issiscv462218
Questioner

Synchronized 사용 시 스프링의 트랜잭션 메커니즘과 같은 원리 때매 그런거였군요! 감사하니다.

issiscv462218's profile image
issiscv462218

asked

Ask a question