Is it possible to have this behavior:
One thread (T1) calls some method, for instance, compute(10);
While that function is still executing, another thread calls it again (with other parameters), say, compute(20);
If the method
public int compute(int i) {
return i+20;
}
will each thread get the correct result?
I expect that T1 gets 20, and T2 gets 40.
Since you use local variables only (method parameters are local), yes it is safe.
If you would use instance variables or static variables, then you should have
synchronizedeveryreadandwriteto the variables.