primitive datatypes are atomic in java
atomic, java, race-condition
Solution
When I have 2 Threads that increment and decrement on a int variable than sometimes i still got race conditions.
Yes, you will - because even though the "get" and "set" operations on the `int` variable are each atomic, that doesn't mean the "increment" operation is atomic.
Is atomic in this case every single operation (getfield, iadd...) and not the full addition?
Yes, exactly. It's not actually the primitive types are atomic - it's read and write operations that are atomic. That's a big difference.
Problem
I read that primitive datatypes like boolean, byte, short, char, int and float are atomic. 64-bit datatypes like long and double are not. But what does this mean? When I have 2 Threads that increment and decrement on a int variable than sometimes i still got race conditions. for example the bytecode of adding an amount to a variable. ``` getfield #2 <Field int amount> iload_1 iadd putfield #2 <Field int amount> ``` Is atomic in this case every single operation (getfield, iadd...) and not the full addition?