JAVA/java
[java] AtomicInteger
닉의네임
2023. 4. 13. 12:22
반응형
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;
반응형