Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Implement your own Java readers and writers problem for a circular buffer. Use as references the pseudocodes of assessment Concurrent Program of this module

Java
image text in transcribed
image text in transcribed
image text in transcribed
Implement your own Java readers and writers problem for a circular buffer. Use as references the pseudocodes of assessment "Concurrent Program" of this module and the case studied in section "Java Multithreading: Circular Buffer in Java." (see Figures 614 . 621). Upload two source files with extension. java that contain the source code of your application. One flle will have your dass MyCircularBuffer and other files will have the class My CircularBuffer Test. Note: Before submitting your application, you should edit, compile your application to guarantee the compiler produces a class fle (without complation and execution erross) which contains java bytecode which can be executed on the Java Virtual Machine (JVM) 1 Fig. 6.6: sircularBuffer.java 2 CircularBufifer synchronizes access to an array of 3// shared butfers. 5 public class CircularBuffer implements Buffer 6\{ 1/ each array element is a buffer private int buffers []={1,1,1}; 1/ occupiedBuffers maintains count of occupied buffers private int occupiedBuffers = 0 ; I variables that maintain read and write buffer Tocations private int readlocation - 0 ; private int writelocation = o; If place value into buffer public synchronized void set( int value) \{ If get name of thread that ca7led this method String name - Thread, currentThreadO. getName O; 1 1 , Fig. 6.7. ficelariuffertest.java 2 cinculariuffertest shows two threads manipulating a 3 verercular barfer. 4 Yeset up the producer and consumer threads and start them 6 public class CircularBuffertest 789fpub7icstaticvoidmain(Stringargs[])& Worceateshared object for threads: use a reference 10150. CircularBuffer rather than a Buffer reference Wiso inyoke SincularBuffer method createstateoutput Circularbuffer sharedlocation = new CircularBufferO: System.err.printin( sharedLocation, createstateoutput O ): Miset up threads Producer producer = new Producer( sharedLocation ): Consumer consumer = new Consumer ( sharedtocation ) : producer.start@; 1/ start producer chread consurer. start(); if start consumer thread 3/l end main I If end class Circularfuffortest

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions