Write a multi-class multithreaded Java program that simulates multiple sleeping barbers, all in one barbershop that has a finite number of chairs in the waiting room. Each customer is instantiated from a single Customer class, each barber is instantiated from a single Barber class. The semaphore version with a single barber is Program 4.8
Use a single monitor object instantiated from a class Salon for synchronization. Do not mechanically translate semaphore code into monitor code! Each customer thread and each barber thread invokes synchronized monitor method(s) for synchronization. No semaphores are allowed. No synchronized blocks are allowed, only synchronized methods. No busy waiting is allowed. No calls to nap inside a synchronized method are allowed (do not nap while holding the monitor object's lock, that is, while inside a synchronized method or while inside a method called by a synchronized method). Do you see why?
Since each barber has its own area of the salon in which to cut hair, the barbers can cut hair concurrently if several customers enter the shop wanting haircuts.
Make sure that customers get haircuts in the order they enter the salon, that is first-come-first-served, also called FIFO. The salon would get a bad reputation if the barbers showed favoritism to some customers or cut hair in a random order. Would you go to such a salon?
Do not worry about the barbers themselves cutting in a fair order with respect to each other. In other words, if barber A finishes cutting a customer followed a bit later by barber B finishing cutting, it is acceptable for barber B to get another customer to cut before barber A.
The input data consist of six integer (int) numbers: C, B, g, c, W, and runtime. These represent the number of customers, the number of barbers, the upper bound on customer hair growing time for the random number generator, the upper bound on hair cutting time for the random number generator, the number of waiting room chairs, and the simulation runtime, respectively. The number runtime controls how long the whole program runs, i.e., there is a nap(1000*runtime) in the main method. You must parse these five numbers from the command line using the GetOpt class (Library Class 2.1). The command line has the form
Remember the flaw in the Jurassic Park problem! Make sure that a customer and the specific barber cutting that customer's hair are properly synchronized.
Stress test your program: one customer and one barber, many customers and few barbers, many barbers and few customers, one chair, more than enough chairs.
Animate your program using XtangoAnimator.