Do different threads accessing method “foo” have their own copy of local variables, or it is needed to make this method synchronized?
class X {
static returnType foo( Object arg) {
Object localvar;
// perform some calculation based on localvar and arg.
// no non-local variable is used i.e: this is a utility method.
// return something.
}
}
You don’t need to synchronize that method. The local variable gets created in the current thread’s “memory space” and there is no way that it will get accessed by any other thread (from what you’ve shown above).