I would like to know if thread safety already plays a role when handling parameters of members in Java.
Say you have a method of an API
boolean moreThanTen(long value) {
if(value > 10) return true;
else return false;
}
would this method be thread safe?
I imagine it would since every thread has its own stack for local variables, and primitives are all stored in this local stack.
The only thing that makes me unsure is the fact that a long
would be two separate reads and thus is generally not thread safe.
My question is: can I be sure that the parameter of a method gets copied atomically? So when using a primitive as a parameter (even float
/long
) can I be sure that during copying it to a local variable thread safety won't be an issue?