Question: ( c ) The class Book, listed below, is thread safe but may deadlock. Explain why and re - write it so that deadlocks cannot
c The class Book, listed below, is thread safe but may deadlock. Explain why and rewrite it
so that deadlocks cannot occur.
class Book
private String title;
private Lock lock new ReentrantLock;
BookString ttitle t;
String title
lock.lock;try return title;finallylockunlock;
void setString nt
lock.lock;
trytitle nt;finallylockunlock;
public boolean equalsObject p
lock.lock;
try
Book b Bookp;
block.lock;
try returntitleequalsbtitle;
finallyblock.unlock;
finallylockunlock;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
