This code is not thread safe. The instance method will be synchronized in the instance, if you have multiple instances, they will not use the same monitor, and therefore updates can be interleaved.
You either need to remove the statics from the value field, or add a static method to the increment() method.
In addition, since you created the value public, there is an additional problem, the value can be changed or read outside of this method without using synchronization, which can lead to reading old values.
Thus, changing your code to the following will make it thread safe:
public class IncreaseTest { private int value = 0; public synchronized int increment() { return value++; } }
source share