Question: Please also check for compile and run time errors. Project 4-2 You will write a Java program that uses synchronization techniques to simulate traffic from

Please also check for compile and run time errors. Project 4-2 YouPlease also check for compile and run time errors.

Project 4-2 You will write a Java program that uses synchronization techniques to simulate traffic from two directions crossing a one-lane bridge. Java program that uses either semaphores or Java synchronization to control access Assignment: Write a multithreaded to a one-lane bridge. One thread should simulate southbound vehicles and another thread should simulate northbound vehicles. The vehicles do not have a reverse gear, so the bridge would become deadlocked if both a southbound vehicle and a northbound vehicle were allowed to drive onto the bridge at the same time. Therefore, mutual exclusion must be enforced. Your solution should avoid both deadlock and starvation (e.g. the bridge being monopolized by southbound vehicles while the northbound vehicles never get to cross). Vehicles traveling in either direction should wait (sleep) for some amount of time, then attempt to cross. Once a vehicle is on the bridge, it should sleep for some amount of time to simulate how long it takes to drive across the bridge. Output a message when each vehicle drives onto the bridge and another message when that vehicle has completed the crossing. Simulate several vehicles traveling in each direction

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 Databases Questions!