Code example for ReentrantReadWriteLock

Methods: readLockwriteLock

    Lock readLock;
    Lock writeLock;
    public RequestManager(Map bookList) {
        this.bookList = bookList;
        lock = new ReentrantReadWriteLock();
        readLock = lock.readLock();
        writeLock = lock.writeLock();
    public String getBookList() {
        return ListRequest.execute(bookList, readLock);
    public String reserveBook(int bookID, int userID) {
        return ReserveRequest.execute(bookID, userID, bookList, writeLock);
    public String loanBook(int bookID, int userID) {
        return LoanRequest.execute(bookID, userID, bookList, writeLock);
Connect your IDE to all the code out there  Get Codota for Java