Although this question asked about synchronization within the context of traditional threads,
a solution to the problem could be to use a more modern approach using the
concurrent package.
The ReadWriteLock from the concurrent package requires the following imports:
Code: Select all
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;