Search

트랜잭션 readOnly 전파

테스트 환경
1번 서비스 메서드와 2번 서비스 메서드
1번 서비스 메서드에서 2번 서비스 메서드를 호출
두 메서드 모두 트랜잭션 어노테이션 적용
2번 서비스 메서드가 REQUIRED 일 때
1번 서비스 메서드만 readOnly 일 때
1번, 2번 메서드 모두 readOnly → 전파됨
2번 서비스 메서드만 readOnly 일 때
1번, 2번 메서드 모두 readOnly X → readOnly=false 도 전파됨
2번 서비스 메서드가 REQUIRES_NEW 일 때
2번 서비스 메서드만 readOnly 일 때
2번 메서드만 readOnly
1번과 2번에서 두 쓰레드로컬이 같다. 근데 왜 다르지?
The 'requires_new' propagation creates a new transaction for the second transaction, independent of the first transaction. Although both transactions may be executed within the same thread, they have separate transactional contexts.
When the second transaction starts with 'requires_new', it initializes its own thread-local transactional context, including the read-only flag. In this case, the read-only flag is explicitly set to true for the second transaction, overriding any previous settings from the first transaction.
Even though both transactions may be running in the same thread, the transaction management framework ensures that the thread-local transactional context is isolated and correctly reflects the desired behavior for each individual transaction. This allows for fine-grained control over transactional behavior, including the ability to have different read-only settings within a single thread.
resources.get()
1.
2.
3.