Question: Implement a Java concurrent program using semaphores to access a car park with two gates, the park has a maximum capacity of 5 0 0

Implement a Java concurrent program using semaphores to access a car park with two gates, the park has a maximum capacity of 500 cars. The car runnable is given below:
class Car extends Thread{ Tunnel tunnel;
public Car(Tunnel t){
tunnel = t; }
public void run(){ tunnel.enter();
try{//stay in tunnel for random period int t =(int)(Math.random()*5000); Thread.sleep(t+2000);
}
catch(InterruptedException e){} tunnel.leave();
}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!