Print
카테고리: [ Development ]
조회수: 5035

1. Transaction

트랜잭션의 특성은 다음과 같다.

  1. Atomic - Each unit of work is an all-or-nothing operation
  2. Consistent - Database integrity constraints are never violated
  3. Isolated - Isolating transactions from each other
  4. Durable - Committed changes are permanent

트랜잭션에는 로컬 트랜잭션과 글로벌 트랜잭션이 있다.

  1. 로컬 트랜잭션 (Single Resource) : Transactions managed by underlying resource
  2. 글로벌 (distributed) 트랜잭션 (Multiple Resources) : Transaction managed by separate, dedicated transaction manager

트랜잭션 코드 스타일 예.

try { 
  beginTransaction 
  … 
  commitTransaction 
} catch (Exception e) { 
  rollbackTransaction 
}

2. Propagation

Propagation이 뭘까? propagation은 전파옵션이라고 한다고 한다.  Spring Transaction 선언 시 propagation mode를 설정할 수 있다고 한다.

Transaction Propagation 에는 아래와 같이 7가지가 있다.

  REQUIRED, REQUIRESNEW, MADATORY, NOTSUPPORTED, SUPPORTS, NEVER, NESTED

Propagation을 설정하지 않으면 default 값은 REQUIRED 이다.


3. Propagation mode 7가지를 좀 더 살펴 볼까?


4. 가장 많이 쓰는 건?

REQUIRES_NEW 와  REQUIRED이다. 이 둘의 차이점을 보면?

  REQUIRED : 실행 중인 Transaction context 가 있으면 해당 Transaction 내에서 실행하고, 없으면 새로운 Transaction 생성
  REQUIRES_NEW : 기존에 실행 중인 Transaction 유무와 상관 없이 무조건 새로운 Transaction 생성