Static method from servlet

I am 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 is a multi-threaded environment. Is it safe to call such a method from a servlet?

Should I add a synchronize property to this function? My concert deals with the value of the variable c in multithreading.

I am new to Java, so this information will be very helpful.

Danny

+3
source share
4 answers

Until you use static fields, I see no problem. But if you really create a method that multiplies, perhaps you need to rethink some parts of your application.

+4

. - , .

, , , . , .

+6

c - , . .

+4

, . , .

+2

Source: https://habr.com/ru/post/1760999/


All Articles