25 lines
744 B
Java
25 lines
744 B
Java
package semaphore;
|
|
|
|
|
|
public class Main {
|
|
// Maximum number of cars on the queue for a valet parking service
|
|
private static final int QUEUE_SIZE = 10;
|
|
// Simulated number of cars
|
|
public static final int NUM_CARS = 150;
|
|
// Simulated number of valets
|
|
private static final int NUM_VALETS = 5;
|
|
|
|
public static void main(String[] args) {
|
|
// The shared queue
|
|
final Queue<Car> valetQueue = new ValetQueue(QUEUE_SIZE);
|
|
// Starting the threads simulating the cars
|
|
for (int i = 0; i < NUM_CARS; i++) {
|
|
new Thread(new CarSimulation(valetQueue, new Car(i))).start();
|
|
}
|
|
// Starting the threads simulating the valets
|
|
for (int i = 0; i < NUM_VALETS; i++) {
|
|
new Thread(new ValetSimulation(valetQueue), "Valet " + i ).start();
|
|
}
|
|
}
|
|
}
|