Are the primitive data types like int & short thread-safe in Java? I have executed the following code and couldn\'t see expected result 500 som
int
short
I would suggest using classes in java.util.concurrent.atomic. They are designed for thread-safety and in some cases the JVM can take advantage of hardware features to optimize.