This code is working well locally, but fails sometimes when it is deployed. Why?
@WebService is a spring annotation
public class Calculator {
@WebService
public boolean isSumOdd(int sum1, int sum2) {
int result = 0;
result = sum1 + sum2;
if (result % 2 == 1) {
return true;
}
return false;
}
}
// The answer seems to be related that this singleton is not thread-safe but why I have to take care about syncronization ? Every thread doesn't pass his variable to this singleton to get the result? Doesn't it have in his switch context the state of the sum variables?
Does the thread share also the variable inside the scope of the method in a singleton so this could lead to problem? I was thinking that the variable are passed by value and copied and after a context switch the other thread has the possibility to restore his state but I believe that I am wrong.....