Question 3
Given:
Which pair's statements should you insert at lines ** and lines *** (respectively) to acquire and release the most appropriate lock?
rwlock.readLock().acquire();rwlock.readLock().release();
rwlock.readLock().lock();rwlock.readLock().unlock();
rwlock.getLock().acquire(); rwlock.getLock().release();
rwlock.getLock().lock();rwlock.getLock().Unlock();
relock.WriteLock().acquire();rwlock.writeLock().release();
rwlock.writeLock().lock();rwlock.WriteLock().unlock();
Correct answer: B
Explanation:
We need a read lock, not a write lock, we are just reading data, not writing/updating data.To aquire and release the lock the method lock() and unlock are used.Incorrect answers:A: No such methods aquire or release.E, F: We do not need writelock.C, D: No method getlock.Reference: Class ReentrantReadWriteLock
We need a read lock, not a write lock, we are just reading data, not writing/updating data.
To aquire and release the lock the method lock() and unlock are used.
Incorrect answers:
A: No such methods aquire or release.
E, F: We do not need writelock.
C, D: No method getlock.
Reference: Class ReentrantReadWriteLock