I’m writing my Servlet application and would like to use the following static method which will multiply x and y.
public class Helper {
private Helper() {
throw new AssertError();
}
public static int mutltiply(int a, int b) {
int c = a*b;
return c;
}
}
I understand that Servlets are multi threading environment. Is it safe to call such method from the servlet?
should I add synchronize property to this function? My concert is regarding value of c variable under multi threading.
I’m new in Java so this information would be very helpful.
Danny.
As long as you don’t use static fields, I see no problems. But if you’re really creating a method which multiply, maybe you need to rethink some parts of your application.