I’m working on a java project and need support to help me study.Producer/Consumer
• You will create a system that implements one of the classic multi-thread synchronization
problems.
• We will use one of Java’s collection classes to make our synchronization task easy:
ArrayBlockingQueue.
o The ArrayBlockQueue class handles the synchronization tasks for us.
o It’s a generic class, and we will use it to hold strings.
o It’s documentation can be found here:
https://docs.oracle.com/javase/7/docs/api/java/uti…
e.html
Read the initial description there to understand how it works.
o You can create one with it’s constructor:
ArrayBlockingQueue(int capacity,boolean fair)
§ Use a relatively small capacity like 5 or 10. Make the fair parameter true
such that messages are queued in FIFO order.
o To write a message to the queue you use: public void put(E e)
o To read a message from the queue you use: public E take()
o You should create the queue in your main class, and pass it to the Producers
and Consumers in their constructors.
• Your system will consist of several Java classes:
o Main – This will contain the main() function, create the queue and the producer
and consumer objects and start them.
o Producer – This class will produce messages that will be sent to a queue. It will
run in a loop, writing Java Strings to the queue. Make the strings distinctive, with
perhaps a message number included in them. Also, delay between sending
messages (perhaps a random one as was used in the Race Condition example).
o Consumer – This class will read messages from the queue. It will run in a loop,
reading Java Strings from the queue and printing them to standard output. You
could also delay between reading messages (perhaps a random one as was
used in the Race Condition example).
o Start with one each of the Producer and Consumers to start.
o When that is working, keep one Consumer object, but create multiple Producer
objects (In this case you might want to have a Producer id number included in
your String message).
• Submit all of your Java files to Blackboard, either individually or as a .zip file.
Requirements: I need it as executable .java file.