Documentation - Laboratory 5: Answer The Following Questions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Documentation – Laboratory 5

Answer the following questions:


A. Using synchronized methods in ProducerConsumer we ensure that the functions wait for each
other, and never run in the same time.
B. The notify() method alerts the other thread to start and the wait() method allows this thread to
wait until certain condition is met.

Make the program produce one item that the consumer immediately
consumes.
First of all I had a closer look at all the classes given to better understand how to program works, after
studying the program it was clear that the change had to be made in the produce() method in the
ProducerConsumer class so I changed the method so the produce function will only make one item at a
time and then notifies the other thread to consume it.

Before After

Bellow we can also see the new output of the application:

You might also like