I have two threads. One invokes the update method of a class that modifies a variable. Another invokes the update method of a class that reads the variable. Only one thread
If there is one and only one thread that writes to variable you can get away with making it volatile. Otherwise see the answer with AtomicInteger. Only volatile will work in case of only one writing thread because there is only one writing thread so it always has the right value of variable.
variable
volatile
AtomicInteger