I would like to know if thread safety plays when handling element parameters in Java.
Let's say you have an API method
boolean moreThanTen(long value) { if(value > 10) return true; else return false; }
will this method be a safe thread?
I assume that since each thread has its own stack for local variables, and the primitives are stored in this local stack.
The only thing that makes me unsure is the fact that long will be two separate reads and, as a rule, is not thread safe.
My question is: can I be sure that the method parameter is copied atomically? Therefore, when using a primitive as a parameter (even float / long ), I can be sure that when copying it to a local variable, thread safety will not be a problem?
Thanks.
source share