Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

송만이

AtomicBoolean 본문

카테고리 없음

AtomicBoolean

송만 2024. 2. 7. 09:27

AtomicBoolean 은 **다중 스레드 환경에서 변수를 변경하는 경우, 스레드 간 동기화 문제가 발생할 수 있는데** 그걸 해결해주는 클래스이다.

단순히 boolean값으로 처리를 했을 때 분명 값이 바뀌어야하는데 안 바뀌는 이슈가 있었는데 이 AtomicBoolean 으로 해결을 했었다.

public static void main(String[] args) {
	AtomicBoolean atom = new AtomicBoolean(true); >> 인자에 따로 넣지 않으면 기본값은 false이다.
    
    .....
    
    if(false){
    	atom.set(false); >> 값 변경은 변수.set()을 하면 된다.
    }
    
    log.info(atom.get());  >> 값을 가져올 때는 변수.get()을 하면 된다.
   
}