Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide screenshots of the output as well as the code. Project 4-2 You will write a Java program that uses synchronization techniques to simulate

Please provide screenshots of the output as well as the code. image text in transcribed
Project 4-2 You will write a Java program that uses synchronization techniques to simulate traffic from two directions crossing a one-lane bridge. Assignment: Write a multithreaded Java program that uses synchronized methods (Section 7.4.1), reentrant locks (Section 7.4.2), or semaphores (Section 7.4.3) to control access to a one- lane bridge. One thread should simulate westbound vehicles and another thread should simulate eastbound vehicles. The vehicles do not have a reverse gear, so the bridge would become deadlocked if both a westbound vehicle and an eastbound vehicle were allowed to drive onto the bridge at the same time. Therefore, mutual exclusion must be enforced on the use of the bridge. Your solution should avoid both deadlock and starvation (e.g. the bridge being monopolized by westbound vehicles while the eastbound 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 (at least five) vehicles traveling in each direction. To help you get started, I am including a zipped folder with this assignment handout. The folder contains example Java code provided by the authors of our textbook. Their code includes examples of how to create and start multiple threads, how to create synchronized methods, and how to make a thread go to sleep

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions