Hi,
I read in the Javadoc for JDK 5.0 that we can "simulate"
synchronized methods with the
java.util.concurrent.locks.ReentrantLock-class. Consider we have something like this:
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?
Or did I understand something wrong?
Stefan