Quantcast
Channel: What is a race condition? - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by Aleksei Moshkov for What is a race condition?

$
0
0

You can prevent race condition, if you use "Atomic" classes. The reason is just the thread don't separate operation get and set, example is below:

AtomicInteger ai = new AtomicInteger(2);ai.getAndAdd(5);

As a result, you will have 7 in link "ai". Although you did two actions, but the both operation confirm the same thread and no one other thread will interfere to this, that means no race conditions!


Viewing all articles
Browse latest Browse all 20

Trending Articles