Quantcast
Channel: AtomicInteger vs synchronized getters/setters - Stack Overflow
Browsing latest articles
Browse All 3 View Live

Answer by Péter Török for AtomicInteger vs synchronized getters/setters

As @Gray noted, there is a possibility for a race condition here.Calling get and then set is not an atomic operation. The Atomic* classes offer a lock-free atomic conditional update operation,...

View Article


Answer by Gray for AtomicInteger vs synchronized getters/setters

Is this class thread-safe?Yes it is.Thread 1 calls setA(100) and enters the function but did not yet call a.set(100) and Thread 2 concurrently calls getA(). Is it possible for Thread 2 to see 80? Yes....

View Article


AtomicInteger vs synchronized getters/setters

Is this class thread-safe? Is it possible to see inconsistent values? Lets say initially a's value is 80. Thread 1 calls setA(100) and enters the function but did not yet call a.set(100) and Thread 2...

View Article
Browsing latest articles
Browse All 3 View Live


Latest Images