Follow these steps to implement the example:
- Create a class named MyLock that extends the ReentrantLock class:
public class MyLock extends ReentrantLock {
- Implement getOwnerName(). This method returns the name of the thread that has control of a lock (if any), using the protected method of the Lock class called getOwner():
public String getOwnerName() { if (this.getOwner()==null) { return "None"; } return this.getOwner().getName(); }
- Implement getThreads(). This method returns a list of threads queued in a lock, using the protected method of the Lock class called getQueuedThreads():
public Collection<Thread> getThreads() { return this.getQueuedThreads(); }
- Create a class named Task that implements the Runnable ...