Follow these steps to implement the example:
- Create a class named PrintQueue that will implement the print queue:
public class PrintQueue {
- Declare a Lock object and initialize it with a new object of the ReentrantLock class in the constructor. The constructor will receive a Boolean parameter we will use to specify the fair mode of the Lock:
private Lock queueLock; public PrintQueue(booleanfairMode) { queueLock = new ReentrantLock(fairMode); }
- Implement the printJob() method. It will receive Object as a parameter and it will not return any value:
public void printJob(Object document){
- Inside the printJob() method, get control of the Lock object by calling the lock() method:
queueLock.lock();
- Then, include ...