Our first design, the big lock design, allows only one thread at a time! The following class illustrates this:Â
public class BigLockHashSet<T> extends HashSet<T> {
final Lock lock;
final int LIST_LEN_THRESHOLD = 100;
public BigLockHashSet(int capacity) {
super(capacity);
lock = new ReentrantLock();
}
As shown in the preceding code, the class is a subclass of HashSet<T> and uses a ReentrantLock. As noted earlier, a reentrant lock is one that allows the owner thread to reacquire it. The LIST_LEN_THRESHOLD constant is used in the shouldResize() method that is described in the next section.
The lock() and unlock() methods are overridden, and they just ignore the x parameter. The methods are shown in the following code:Â
@Override
protected void unlock(T x) {
lock.unlock();
}
@Override
protected void...