5AMSUNG

[java] AtomicInteger 본문

카테고리 없음

[java] AtomicInteger

짝구이 2023. 4. 21. 11:33
반응형

AtomicInteger 여러 스레드에서 동시에 액세스할 수 있는 다중 스레드 환경에서 원자 정수 카운터로 사용할 수 있는 Java의 클래스입니다.

AtomicInteger는 synchronized 보다 적은 비용으로 동시성을 보장할 수 있습니다.

 

 

y = atomic.get();  ->  y = i;

y = atomic.incrementAndGet(); -> y = ++i;

y = atomic.getAndIncrement(); -> y = i++;

y = atomic.decrementAndGet(); -> y = --i;

y = atomic.getAndDecrement(); -> y = i--;

y = atomic.addAndGet(x); -> i = i + x; y = i;

y = atomic.getAndAdd(x); -> y = i; i = i + x;

atomic.set(x); -> i = x;

y = atomic.getAndSet(x); -> y = i; i = i + x;

반응형