When a thread executes the code of method foo, another thread can execute the code of method bar at "the same time". But how do I replace the synchronized keyword? At first, I considered implementing a single lock using java.util.concurrent.locks.ReentrantLock:
But with this solution it is no longer possible that a thread executes foo() while another thread executes bar() since only one thread can hold the lock. Does that mean that we need to introduce a variable of class java.util.concurrent.locks.ReentrantLock for every method we want to synchronize?