SlideShare a Scribd company logo
1 of 51
Question I
You are going to use the semaphores for process
synchronization. Therefore, you are asked to develop a
consumer and producer multithreaded program.
Let us assume, that we have a thread (producer, we will call it
producer_thread) reading data (positive integer numbers) from
the keyboard, entered by a user to be stored in an array
(dynamic array). (Assume that the array can hold all numbers
entered without overflow.)
Another thread (consumer, we will call it consumer_thread)
should read data from the array and write them into a file. This
thread should run concurrently with the producer
(producer_thread).
Your program should make sure that the consumer_thread can
read from the array only after the producer_thread has stored
new data. Both threads will stop when the user enters a negative
number (well synchronized).
Another thread (testing_thread) should start reading the array
data as well as the file data and display them on the screen in
order to verify if the consumer and producer have worked in a
correctly synchronized fashion. This thread should not be
synchronized with other threads, it is intended for testing that
consumer thread is synchronized with produce thread.
Provide your tutor with the source code as well as screen
snapshots that show the work of the testing_thread.
1
TM298_TMA_Q2/build.xml
Builds, tests, and runs the project TM298_TMA_Q2.
TM298_TMA_Q2/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
TM298_TMA_Q2/nbproject/build-impl.xml
Must set src.dir
Must set test.src.dir
Must set build.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.jar
Must set javac.includes
No tests executed.
Must set JVM to use for profiling in profiler.info.jvm
Must set profiler agent JVM arguments in
profiler.info.jvmargs.agent
Must select some files in the IDE or set javac.includes
To run this application from the command line without
Ant, try:
java -jar "${dist.jar.resolved}"
Must select one file in the IDE or set run.class
Must select one file in the IDE or set run.class
Must select one file in the IDE or set debug.class
Must select one file in the IDE or set debug.class
Must set fix.includes
This target only works when run from inside the NetBeans
IDE.
Must select one file in the IDE or set profile.class
This target only works when run from inside the NetBeans
IDE.
This target only works when run from inside the NetBeans
IDE.
This target only works when run from inside the NetBeans
IDE.
Must select one file in the IDE or set run.class
Must select some files in the IDE or set test.includes
Must select one file in the IDE or set run.class
Must select one file in the IDE or set applet.url
Must select some files in the IDE or set javac.includes
Some tests failed; see details above.
Must select some files in the IDE or set test.includes
Some tests failed; see details above.
Must select some files in the IDE or set test.class
Must select some method in the IDE or set test.method
Some tests failed; see details above.
Must select one file in the IDE or set test.class
Must select one file in the IDE or set test.class
Must select some method in the IDE or set test.method
Must select one file in the IDE or set applet.url
Must select one file in the IDE or set applet.url
TM298_TMA_Q2/nbproject/genfiles.properties
build.xml.data.CRC32=f05f63ba
build.xml.script.CRC32=4dc8f402
[email protected]
# This file is used by a NetBeans-based IDE to track changes in
generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will
never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=f05f63ba
nbproject/build-impl.xml.script.CRC32=6ecbbebf
nbproject/[email protected]
TM298_TMA_Q2/nbproject/private/private.properties
compile.on.save=true
user.properties.file=/Users/macbook/Library/Application
Support/NetBeans/8.2/build.properties
TM298_TMA_Q2/nbproject/project.properties
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.
dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection
transport:
#debug.transport=dt_socket
debug.classpath=
${run.classpath}
debug.test.classpath=
${run.test.classpath}
# Files in build.classes.dir which should be excluded from
distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/TM298_TMA_Q2.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=
${javac.classpath}:
${build.classes.dir}
javac.test.processorpath=
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=tm298_tma_q2.TM298_TMA_Q2
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=
${javac.classpath}:
${build.classes.dir}
# Space-separated list of JVM arguments used when running the
project.
# You may also define separate properties like run-sys-
prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-
prop.name=value:
run.jvmargs=
run.test.classpath=
${javac.test.classpath}:
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
TM298_TMA_Q2/nbproject/project.xml
org.netbeans.modules.java.j2seproject
TM298_TMA_Q2
TM298_TMA_Q2/src/tm298_tma_q2/ArrayStorage.javaTM298_
TMA_Q2/src/tm298_tma_q2/ArrayStorage.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassArrayStorage{
privateInteger[] arrayInt;
privateint size;
privateint item_Counter;// number of items still not taken from i
n the array
privateint index_in;// array index for the writer
privateint index_out;// array index for teh reader
publicArrayStorage(Integer[] arrayInt){
this.arrayInt = arrayInt;
this.size = arrayInt.length;
this.item_Counter =0;
this.index_in =0;
this.index_out =0;
}
publicvoid put_item(int data){
if(this.item_Counter < size){
arrayInt[index_in]= data;
this.item_Counter++;
index_in =(index_in +1)% size;// circular buffer
}
}
publicint take_item(){
int data =0;
if(this.item_Counter !=0){
data = arrayInt[index_out];
this.item_Counter--;//
index_out =(index_out +1)% size;// circular buffer
}
return data;
}
/**
* Get the value of index_out
*
* @return the value of index_out
*/
publicint getIndex_out(){
return index_out;
}
/**
* Set the value of index_out
*
* @param index_out new value of index_out
*/
publicvoid setIndex_out(int index_out){
this.index_out = index_out;
}
/**
* Get the value of index_in
*
* @return the value of index_in
*/
publicint getIndex_in(){
return index_in;
}
/**
* Set the value of index_in
*
* @param index_in new value of index_in
*/
publicvoid setIndex_in(int index_in){
this.index_in = index_in;
}
/**
* Get the value of item_Counter
*
* @return the value of item_Counter
*/
publicint getItem_Counter(){
return item_Counter;
}
/**
* Set the value of item_Counter
*
* @param item_Counter new value of item_Counter
*/
publicvoid setItem_Counter(int item_Counter){
this.item_Counter = item_Counter;
}
/**
* Get the value of size
*
* @return the value of size
*/
publicint getSize(){
return size;
}
/**
* Set the value of size
*
* @param size new value of size
*/
publicvoid setSize(int size){
this.size = size;
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Consumer.javaTM298_TM
A_Q2/src/tm298_tma_q2/Consumer.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassConsumerextendsThread{
privateArrayStorage arrayData;
privateString fileName;
/**
* Get the value of arrayData
*
* @return the value of arrayData
*/
publicConsumer(ArrayStorage arrayData,String fileName){
super();
this.arrayData = arrayData;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
// read the data from the arry and save them to file
// stops when negative number is read
}
publicConsumer(String name){
super(name);
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Producer.javaTM298_TM
A_Q2/src/tm298_tma_q2/Producer.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassProducerextendsThread{
privateArrayStorage test;
privateString fileName;
publicProducer(ArrayStorage test,String fileName){
this.test = test;
this.fileName=fileName;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
//ask the user to enter Integers, stop when a negative number is
enetred
//put the integer in teh array
// save it in a file to be compared with reader data
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Testing_Thread.javaTM29
8_TMA_Q2/src/tm298_tma_q2/Testing_Thread.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassTesting_ThreadextendsThread{
String readerFileName="reader.txt";
String writerFileName="writer.txt";
publicTesting_Thread(String readerFileName,String writerFileN
ame){
this.readerFileName=readerFileName;
this.writerFileName=writerFileName;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
//open read and writer files
//read the data from the reader file and compare them to the con
etent of writer file
// repeat this until the end of the file
// if all data macthes, then you can tell that both threads cosnum
er and producers are well synchronized
}
}
TM298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.javaTM
298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclass TM298_TMA_Q2 {
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args){
// TODO code application logic here
String readerFileName="reader.txt";
String writerFileName="writer.txt";
Integer[] arrayInt=newInteger[20];
Thread mainThread=Thread.currentThread();
ArrayStorage shared_buffer=newArrayStorage(arrayInt);
Consumer consumer=newConsumer(shared_buffer, readerFileNa
me);
Producer producer=newProducer(shared_buffer,writerFileName)
;
Testing_Thread test_sync=newTesting_Thread(readerFileName,
writerFileName);
consumer.start();
producer.start();
try{
consumer.join();// wait until the consumer finishes reading
data form the shared buffer
}
catch(Exception e){
System.out.println(e);
}
test_sync.start();
System.out.print("Mission accomplished");
}
}

More Related Content

Similar to Question IYou are going to use the semaphores for process sy.docx

CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxmonicafrancis71118
 
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docxshericehewat
 
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docxOrdering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docxhopeaustin33688
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docxgilpinleeanna
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnitGreg.Helton
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
HW_6-1build.xml Builds, tests, and runs the project HW.docx
HW_6-1build.xml      Builds, tests, and runs the project HW.docxHW_6-1build.xml      Builds, tests, and runs the project HW.docx
HW_6-1build.xml Builds, tests, and runs the project HW.docxadampcarr67227
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontendHeiko Hardt
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkRapidValue
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java DevelopersYakov Fain
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxssuser454af01
 
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification SolutionsAdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutionsjamieayre
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxcurwenmichaela
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxhartrobert670
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 

Similar to Question IYou are going to use the semaphores for process sy.docx (20)

CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
 
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
 
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docxOrdering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docx
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 
Readme
ReadmeReadme
Readme
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
HW_6-1build.xml Builds, tests, and runs the project HW.docx
HW_6-1build.xml      Builds, tests, and runs the project HW.docxHW_6-1build.xml      Builds, tests, and runs the project HW.docx
HW_6-1build.xml Builds, tests, and runs the project HW.docx
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontend
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docx
 
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification SolutionsAdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
 
Maze
MazeMaze
Maze
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 

More from audeleypearl

Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docxMr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docxaudeleypearl
 
Movie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docxMovie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docxaudeleypearl
 
Motivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docxMotivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docxaudeleypearl
 
Mother of the Year In recognition of superlative paren.docx
Mother of the Year         In recognition of superlative paren.docxMother of the Year         In recognition of superlative paren.docx
Mother of the Year In recognition of superlative paren.docxaudeleypearl
 
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docxMrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docxaudeleypearl
 
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docxMr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docxaudeleypearl
 
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docxMr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docxaudeleypearl
 
Moving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docxMoving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docxaudeleypearl
 
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docxMr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docxaudeleypearl
 
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docxMr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docxaudeleypearl
 
Motor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docxMotor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docxaudeleypearl
 
Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxaudeleypearl
 
Most patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docxMost patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docxaudeleypearl
 
Most of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docxMost of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docxaudeleypearl
 
Most people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docxMost people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docxaudeleypearl
 
Most of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docxMost of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docxaudeleypearl
 
Most healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docxMost healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docxaudeleypearl
 
More work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docxMore work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docxaudeleypearl
 
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docxMortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docxaudeleypearl
 
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docxMoral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docxaudeleypearl
 

More from audeleypearl (20)

Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docxMr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
 
Movie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docxMovie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docx
 
Motivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docxMotivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docx
 
Mother of the Year In recognition of superlative paren.docx
Mother of the Year         In recognition of superlative paren.docxMother of the Year         In recognition of superlative paren.docx
Mother of the Year In recognition of superlative paren.docx
 
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docxMrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
 
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docxMr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
 
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docxMr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
 
Moving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docxMoving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docx
 
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docxMr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
 
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docxMr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
 
Motor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docxMotor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docx
 
Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docx
 
Most patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docxMost patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docx
 
Most of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docxMost of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docx
 
Most people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docxMost people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docx
 
Most of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docxMost of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docx
 
Most healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docxMost healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docx
 
More work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docxMore work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docx
 
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docxMortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
 
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docxMoral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

Question IYou are going to use the semaphores for process sy.docx

  • 1. Question I You are going to use the semaphores for process synchronization. Therefore, you are asked to develop a consumer and producer multithreaded program. Let us assume, that we have a thread (producer, we will call it producer_thread) reading data (positive integer numbers) from the keyboard, entered by a user to be stored in an array (dynamic array). (Assume that the array can hold all numbers entered without overflow.) Another thread (consumer, we will call it consumer_thread) should read data from the array and write them into a file. This thread should run concurrently with the producer (producer_thread). Your program should make sure that the consumer_thread can read from the array only after the producer_thread has stored new data. Both threads will stop when the user enters a negative number (well synchronized). Another thread (testing_thread) should start reading the array data as well as the file data and display them on the screen in order to verify if the consumer and producer have worked in a correctly synchronized fashion. This thread should not be synchronized with other threads, it is intended for testing that consumer thread is synchronized with produce thread. Provide your tutor with the source code as well as screen snapshots that show the work of the testing_thread.
  • 2. 1 TM298_TMA_Q2/build.xml Builds, tests, and runs the project TM298_TMA_Q2. TM298_TMA_Q2/manifest.mf Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build TM298_TMA_Q2/nbproject/build-impl.xml
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar
  • 9.
  • 10.
  • 12.
  • 13.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Must select some files in the IDE or set javac.includes
  • 29. To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}"
  • 30. Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class
  • 31. Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE.
  • 32. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE.
  • 33. Must select one file in the IDE or set run.class
  • 34. Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url
  • 35.
  • 36. Must select some files in the IDE or set javac.includes Some tests failed; see details above.
  • 37. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method
  • 38. Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url
  • 40. [email protected] # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=f05f63ba nbproject/build-impl.xml.script.CRC32=6ecbbebf nbproject/[email protected] TM298_TMA_Q2/nbproject/private/private.properties compile.on.save=true user.properties.file=/Users/macbook/Library/Application Support/NetBeans/8.2/build.properties TM298_TMA_Q2/nbproject/project.properties annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources. dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket
  • 41. debug.classpath= ${run.classpath} debug.test.classpath= ${run.test.classpath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/TM298_TMA_Q2.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath= ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath= ${javac.classpath}: ${build.classes.dir} javac.test.processorpath= ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true
  • 42. javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=tm298_tma_q2.TM298_TMA_Q2 manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath= ${javac.classpath}: ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys- prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys- prop.name=value: run.jvmargs= run.test.classpath= ${javac.test.classpath}: ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test TM298_TMA_Q2/nbproject/project.xml org.netbeans.modules.java.j2seproject TM298_TMA_Q2
  • 43. TM298_TMA_Q2/src/tm298_tma_q2/ArrayStorage.javaTM298_ TMA_Q2/src/tm298_tma_q2/ArrayStorage.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassArrayStorage{ privateInteger[] arrayInt; privateint size; privateint item_Counter;// number of items still not taken from i n the array privateint index_in;// array index for the writer privateint index_out;// array index for teh reader publicArrayStorage(Integer[] arrayInt){ this.arrayInt = arrayInt; this.size = arrayInt.length; this.item_Counter =0;
  • 44. this.index_in =0; this.index_out =0; } publicvoid put_item(int data){ if(this.item_Counter < size){ arrayInt[index_in]= data; this.item_Counter++; index_in =(index_in +1)% size;// circular buffer } } publicint take_item(){ int data =0; if(this.item_Counter !=0){ data = arrayInt[index_out]; this.item_Counter--;// index_out =(index_out +1)% size;// circular buffer } return data; } /** * Get the value of index_out * * @return the value of index_out */ publicint getIndex_out(){ return index_out; } /** * Set the value of index_out * * @param index_out new value of index_out
  • 45. */ publicvoid setIndex_out(int index_out){ this.index_out = index_out; } /** * Get the value of index_in * * @return the value of index_in */ publicint getIndex_in(){ return index_in; } /** * Set the value of index_in * * @param index_in new value of index_in */ publicvoid setIndex_in(int index_in){ this.index_in = index_in; } /** * Get the value of item_Counter * * @return the value of item_Counter */ publicint getItem_Counter(){ return item_Counter; } /** * Set the value of item_Counter * * @param item_Counter new value of item_Counter
  • 46. */ publicvoid setItem_Counter(int item_Counter){ this.item_Counter = item_Counter; } /** * Get the value of size * * @return the value of size */ publicint getSize(){ return size; } /** * Set the value of size * * @param size new value of size */ publicvoid setSize(int size){ this.size = size; } } TM298_TMA_Q2/src/tm298_tma_q2/Consumer.javaTM298_TM A_Q2/src/tm298_tma_q2/Consumer.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /**
  • 47. * * @author macbook */ publicclassConsumerextendsThread{ privateArrayStorage arrayData; privateString fileName; /** * Get the value of arrayData * * @return the value of arrayData */ publicConsumer(ArrayStorage arrayData,String fileName){ super(); this.arrayData = arrayData; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates. // read the data from the arry and save them to file // stops when negative number is read } publicConsumer(String name){ super(name); }
  • 48. } TM298_TMA_Q2/src/tm298_tma_q2/Producer.javaTM298_TM A_Q2/src/tm298_tma_q2/Producer.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassProducerextendsThread{ privateArrayStorage test; privateString fileName; publicProducer(ArrayStorage test,String fileName){ this.test = test; this.fileName=fileName; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates. //ask the user to enter Integers, stop when a negative number is enetred //put the integer in teh array // save it in a file to be compared with reader data
  • 49. } } TM298_TMA_Q2/src/tm298_tma_q2/Testing_Thread.javaTM29 8_TMA_Q2/src/tm298_tma_q2/Testing_Thread.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassTesting_ThreadextendsThread{ String readerFileName="reader.txt"; String writerFileName="writer.txt"; publicTesting_Thread(String readerFileName,String writerFileN ame){ this.readerFileName=readerFileName; this.writerFileName=writerFileName; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates.
  • 50. //open read and writer files //read the data from the reader file and compare them to the con etent of writer file // repeat this until the end of the file // if all data macthes, then you can tell that both threads cosnum er and producers are well synchronized } } TM298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.javaTM 298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclass TM298_TMA_Q2 { /** * @param args the command line arguments */ publicstaticvoid main(String[] args){ // TODO code application logic here String readerFileName="reader.txt";
  • 51. String writerFileName="writer.txt"; Integer[] arrayInt=newInteger[20]; Thread mainThread=Thread.currentThread(); ArrayStorage shared_buffer=newArrayStorage(arrayInt); Consumer consumer=newConsumer(shared_buffer, readerFileNa me); Producer producer=newProducer(shared_buffer,writerFileName) ; Testing_Thread test_sync=newTesting_Thread(readerFileName, writerFileName); consumer.start(); producer.start(); try{ consumer.join();// wait until the consumer finishes reading data form the shared buffer } catch(Exception e){ System.out.println(e); } test_sync.start(); System.out.print("Mission accomplished"); } }