commit 109a610ee5884e3e1258b0d39efa22b515d3ea3a Author: mirimatcode Date: Wed Apr 6 22:41:27 2022 +0200 primo commit diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bd8be9d --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project ProduttoreConsumatore. + + + diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/produttoreconsumatore/Cesta.class b/build/classes/produttoreconsumatore/Cesta.class new file mode 100644 index 0000000..557c1b1 Binary files /dev/null and b/build/classes/produttoreconsumatore/Cesta.class differ diff --git a/build/classes/produttoreconsumatore/Consumatore.class b/build/classes/produttoreconsumatore/Consumatore.class new file mode 100644 index 0000000..21d96bd Binary files /dev/null and b/build/classes/produttoreconsumatore/Consumatore.class differ diff --git a/build/classes/produttoreconsumatore/Produttore.class b/build/classes/produttoreconsumatore/Produttore.class new file mode 100644 index 0000000..f1e10f4 Binary files /dev/null and b/build/classes/produttoreconsumatore/Produttore.class differ diff --git a/build/classes/produttoreconsumatore/ProduttoreConsumatore.class b/build/classes/produttoreconsumatore/ProduttoreConsumatore.class new file mode 100644 index 0000000..4c3b212 Binary files /dev/null and b/build/classes/produttoreconsumatore/ProduttoreConsumatore.class differ diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..f519539 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..29699e5 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=201797c6 +build.xml.script.CRC32=d55de831 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# 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=201797c6 +nbproject/build-impl.xml.script.CRC32=25c87c97 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..26ce0ca --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=/home/nfutu/.netbeans/8.0.2/build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..25c6f6a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/home/nfutu/Extra/Dropbox/Progetto%20PAS/ProduttoreConsumatore/src/produttoreconsumatore/ProduttoreConsumatore.java + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..56f1e79 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,73 @@ +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}/ProduttoreConsumatore.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.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +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=produttoreconsumatore.ProduttoreConsumatore +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 diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..151f124 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ProduttoreConsumatore + + + + + + + + + diff --git a/src/produttoreconsumatore/Cesta.java b/src/produttoreconsumatore/Cesta.java new file mode 100644 index 0000000..916cc5d --- /dev/null +++ b/src/produttoreconsumatore/Cesta.java @@ -0,0 +1,28 @@ +package produttoreconsumatore; + +public class Cesta +{ + int numeroPanini; + + public Cesta() + { + this.numeroPanini = 0; + } + + public void inserisci() + { + numeroPanini++; + System.out.println("Panino inserito - Panini nella cesta: " + getPanini()); + } + + public void preleva() + { + numeroPanini--; + System.out.println("Panino prelevato - Panini nella cesta: " + getPanini()); + } + + public int getPanini() + { + return numeroPanini; + } +} \ No newline at end of file diff --git a/src/produttoreconsumatore/Consumatore.java b/src/produttoreconsumatore/Consumatore.java new file mode 100644 index 0000000..7c4ba91 --- /dev/null +++ b/src/produttoreconsumatore/Consumatore.java @@ -0,0 +1,40 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class Consumatore extends Thread +{ + Cesta cesta; + Semaphore semaforo; + Semaphore spazioInserimento; + Semaphore spazioPrelievo; + + public Consumatore(Cesta cesta, Semaphore semaforo, Semaphore spazioInserimento, Semaphore spazioPrelievo) + { + this.cesta = cesta; + this.semaforo = semaforo; + this.spazioInserimento = spazioInserimento; + this.spazioPrelievo = spazioPrelievo; + } + + @Override + public void run() + { + while(true) + try + { + spazioPrelievo.acquire(); + semaforo.acquire(); + cesta.preleva(); + semaforo.release(); + spazioInserimento.release(); + + //Consuma il panino + sleep((int)(Math.random()*1000)); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +} diff --git a/src/produttoreconsumatore/Produttore.java b/src/produttoreconsumatore/Produttore.java new file mode 100644 index 0000000..98b4ef2 --- /dev/null +++ b/src/produttoreconsumatore/Produttore.java @@ -0,0 +1,40 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class Produttore extends Thread +{ + Cesta cesta; + Semaphore semaforo; + Semaphore spazioInserimento; + Semaphore spazioPrelievo; + + public Produttore(Cesta cesta, Semaphore semaforo, Semaphore spazioInserimento, Semaphore spazioPrelievo) + { + this.cesta = cesta; + this.semaforo = semaforo; + this.spazioInserimento = spazioInserimento; + this.spazioPrelievo = spazioPrelievo; + } + + @Override + public void run() + { + while(true) + try + { + //Produce il panino + sleep((int)(Math.random()*1000)); + + spazioInserimento.acquire(); + semaforo.acquire(); + cesta.inserisci(); + semaforo.release(); + spazioPrelievo.release(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +} diff --git a/src/produttoreconsumatore/ProduttoreConsumatore.java b/src/produttoreconsumatore/ProduttoreConsumatore.java new file mode 100644 index 0000000..9c5aa57 --- /dev/null +++ b/src/produttoreconsumatore/ProduttoreConsumatore.java @@ -0,0 +1,20 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class ProduttoreConsumatore +{ + public static void main(String[] args) throws InterruptedException + { + int dimensioneCesta = 100; + Semaphore semaforo = new Semaphore(1); + Semaphore spazioInserimento = new Semaphore(100); + Semaphore spazioPrelievo = new Semaphore(0); + + Cesta cesta = new Cesta(); + + new Produttore(cesta, semaforo, spazioInserimento, spazioPrelievo).start(); + Thread.sleep(10000); + new Consumatore(cesta, semaforo, spazioInserimento, spazioPrelievo).start(); + } +}