diff --git a/java/samples/multithread/GazStation/build.xml b/java/samples/multithread/GazStation/build.xml new file mode 100644 index 0000000..aaf6774 --- /dev/null +++ b/java/samples/multithread/GazStation/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project GazStation. + + + diff --git a/java/samples/multithread/GazStation/build/classes/.netbeans_automatic_build b/java/samples/multithread/GazStation/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/GazStation/build/classes/.netbeans_update_resources b/java/samples/multithread/GazStation/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/GazStation/build/classes/gazstation/Car.class b/java/samples/multithread/GazStation/build/classes/gazstation/Car.class new file mode 100644 index 0000000..bf05ff8 Binary files /dev/null and b/java/samples/multithread/GazStation/build/classes/gazstation/Car.class differ diff --git a/java/samples/multithread/GazStation/build/classes/gazstation/FilingColumn.class b/java/samples/multithread/GazStation/build/classes/gazstation/FilingColumn.class new file mode 100644 index 0000000..2db8ffe Binary files /dev/null and b/java/samples/multithread/GazStation/build/classes/gazstation/FilingColumn.class differ diff --git a/java/samples/multithread/GazStation/build/classes/gazstation/GazProducer.class b/java/samples/multithread/GazStation/build/classes/gazstation/GazProducer.class new file mode 100644 index 0000000..e71e0af Binary files /dev/null and b/java/samples/multithread/GazStation/build/classes/gazstation/GazProducer.class differ diff --git a/java/samples/multithread/GazStation/build/classes/gazstation/GazStation.class b/java/samples/multithread/GazStation/build/classes/gazstation/GazStation.class new file mode 100644 index 0000000..34e9cdb Binary files /dev/null and b/java/samples/multithread/GazStation/build/classes/gazstation/GazStation.class differ diff --git a/java/samples/multithread/GazStation/build/classes/gazstation/MainClass.class b/java/samples/multithread/GazStation/build/classes/gazstation/MainClass.class new file mode 100644 index 0000000..c16d10b Binary files /dev/null and b/java/samples/multithread/GazStation/build/classes/gazstation/MainClass.class differ diff --git a/java/samples/multithread/GazStation/manifest.mf b/java/samples/multithread/GazStation/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/java/samples/multithread/GazStation/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/java/samples/multithread/GazStation/nbproject/build-impl.xml b/java/samples/multithread/GazStation/nbproject/build-impl.xml new file mode 100644 index 0000000..ef8ab78 --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/java/samples/multithread/GazStation/nbproject/genfiles.properties b/java/samples/multithread/GazStation/nbproject/genfiles.properties new file mode 100644 index 0000000..0334824 --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=9cd5ec1b +build.xml.script.CRC32=76050ae8 +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=9cd5ec1b +nbproject/build-impl.xml.script.CRC32=84c4fcda +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/java/samples/multithread/GazStation/nbproject/private/private.properties b/java/samples/multithread/GazStation/nbproject/private/private.properties new file mode 100644 index 0000000..11ff3b8 --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/java/samples/multithread/GazStation/nbproject/private/private.xml b/java/samples/multithread/GazStation/nbproject/private/private.xml new file mode 100644 index 0000000..b3b8b31 --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/private/private.xml @@ -0,0 +1,11 @@ + + + + + + file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/GazStation/src/gazstation/Car.java + file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/GazStation/src/gazstation/GazProducer.java + file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/GazStation/src/gazstation/FilingColumn.java + + + diff --git a/java/samples/multithread/GazStation/nbproject/project.properties b/java/samples/multithread/GazStation/nbproject/project.properties new file mode 100644 index 0000000..fc4f33f --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/project.properties @@ -0,0 +1,74 @@ +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} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/GazStation.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=gazstation.MainClass +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/java/samples/multithread/GazStation/nbproject/project.xml b/java/samples/multithread/GazStation/nbproject/project.xml new file mode 100644 index 0000000..0236956 --- /dev/null +++ b/java/samples/multithread/GazStation/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + GazStation + + + + + + + + + diff --git a/java/samples/multithread/GazStation/src/gazstation/Car.java b/java/samples/multithread/GazStation/src/gazstation/Car.java new file mode 100644 index 0000000..66a4c9d --- /dev/null +++ b/java/samples/multithread/GazStation/src/gazstation/Car.java @@ -0,0 +1,50 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gazstation; + +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +class Car extends Thread{ + public int tank; + private int max = 40; + public String name; + + @Override + public void run() { + while(true){ + fuel(); + try {Thread.sleep(1000);} catch (InterruptedException ex) {} + int fuel = new Random().nextInt(40); + tank -= fuel; + System.out.println(name + ": израсходовал " + fuel + " л. Объем топлива: " + tank); + } + } + + public Car(String name) { + this.name = name; + this.tank = new Random().nextInt(max-20); + } + + public void fuel(){ + int fuel = max - tank; + boolean res = GazStation.getState().column1.getFuel(fuel); + if(!res) { + System.out.println(name + ": не достаточно топлива. Ожидает."); + + try {Thread.sleep(2000);} catch (InterruptedException ex) {} + fuel(); + }else { + tank += fuel; + System.out.println("--------------------------" + name + ": заправил " + fuel + " л. Объем топлива: " + tank); + } + } +} diff --git a/java/samples/multithread/GazStation/src/gazstation/FilingColumn.java b/java/samples/multithread/GazStation/src/gazstation/FilingColumn.java new file mode 100644 index 0000000..b4e5259 --- /dev/null +++ b/java/samples/multithread/GazStation/src/gazstation/FilingColumn.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gazstation; + +import java.util.Random; + +/** + * + * @author denis + */ +class FilingColumn { + + private int bigTank; + private boolean isOrder; + + public FilingColumn (){ + bigTank = new Random().nextInt(500); + isOrder = true; + } + + + public synchronized boolean getFuel(int fuel) { + if(isOrder){ + if(bigTank + + + + + + + + + + Builds, tests, and runs the project GazStation2. + + + diff --git a/java/samples/multithread/GazStation2/build/classes/.netbeans_automatic_build b/java/samples/multithread/GazStation2/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/GazStation2/build/classes/.netbeans_update_resources b/java/samples/multithread/GazStation2/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/GazStation2/build/classes/gazstation2/Car.class b/java/samples/multithread/GazStation2/build/classes/gazstation2/Car.class new file mode 100644 index 0000000..692a7e3 Binary files /dev/null and b/java/samples/multithread/GazStation2/build/classes/gazstation2/Car.class differ diff --git a/java/samples/multithread/GazStation2/build/classes/gazstation2/FilingColumn.class b/java/samples/multithread/GazStation2/build/classes/gazstation2/FilingColumn.class new file mode 100644 index 0000000..fb00ab8 Binary files /dev/null and b/java/samples/multithread/GazStation2/build/classes/gazstation2/FilingColumn.class differ diff --git a/java/samples/multithread/GazStation2/build/classes/gazstation2/GazProducer.class b/java/samples/multithread/GazStation2/build/classes/gazstation2/GazProducer.class new file mode 100644 index 0000000..c8ef3c9 Binary files /dev/null and b/java/samples/multithread/GazStation2/build/classes/gazstation2/GazProducer.class differ diff --git a/java/samples/multithread/GazStation2/build/classes/gazstation2/GazStation.class b/java/samples/multithread/GazStation2/build/classes/gazstation2/GazStation.class new file mode 100644 index 0000000..8578130 Binary files /dev/null and b/java/samples/multithread/GazStation2/build/classes/gazstation2/GazStation.class differ diff --git a/java/samples/multithread/GazStation2/build/classes/gazstation2/MainClass.class b/java/samples/multithread/GazStation2/build/classes/gazstation2/MainClass.class new file mode 100644 index 0000000..913198d Binary files /dev/null and b/java/samples/multithread/GazStation2/build/classes/gazstation2/MainClass.class differ diff --git a/java/samples/multithread/GazStation2/manifest.mf b/java/samples/multithread/GazStation2/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/java/samples/multithread/GazStation2/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/java/samples/multithread/GazStation2/nbproject/build-impl.xml b/java/samples/multithread/GazStation2/nbproject/build-impl.xml new file mode 100644 index 0000000..59dd754 --- /dev/null +++ b/java/samples/multithread/GazStation2/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/java/samples/multithread/GazStation2/nbproject/genfiles.properties b/java/samples/multithread/GazStation2/nbproject/genfiles.properties new file mode 100644 index 0000000..6f6db25 --- /dev/null +++ b/java/samples/multithread/GazStation2/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=9bff76db +build.xml.script.CRC32=def1c8af +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=9bff76db +nbproject/build-impl.xml.script.CRC32=4dede8da +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/java/samples/multithread/GazStation2/nbproject/private/private.properties b/java/samples/multithread/GazStation2/nbproject/private/private.properties new file mode 100644 index 0000000..11ff3b8 --- /dev/null +++ b/java/samples/multithread/GazStation2/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/java/samples/multithread/GazStation2/nbproject/project.properties b/java/samples/multithread/GazStation2/nbproject/project.properties new file mode 100644 index 0000000..3f0144b --- /dev/null +++ b/java/samples/multithread/GazStation2/nbproject/project.properties @@ -0,0 +1,74 @@ +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} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/GazStation2.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=gazstation2.MainClass +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/java/samples/multithread/GazStation2/nbproject/project.xml b/java/samples/multithread/GazStation2/nbproject/project.xml new file mode 100644 index 0000000..7def307 --- /dev/null +++ b/java/samples/multithread/GazStation2/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + GazStation2 + + + + + + + + + diff --git a/java/samples/multithread/GazStation2/src/gazstation2/Car.java b/java/samples/multithread/GazStation2/src/gazstation2/Car.java new file mode 100644 index 0000000..fff0c60 --- /dev/null +++ b/java/samples/multithread/GazStation2/src/gazstation2/Car.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gazstation2; + +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +class Car extends Thread{ + public int tank; + private int max = 40; + public String name; + + @Override + public void run() { + for(int i=0 ; i<20 ; i++){ + fuel(); + try {Thread.sleep(1000);} catch (InterruptedException ex) {} + int fuel = new Random().nextInt(40); + tank -= fuel; + System.out.println(name + ": израсходовал " + fuel + " л. Объем топлива: " + tank); + } + } + + public Car(String name) { + this.name = name; + this.tank = new Random().nextInt(max-20); + } + + public void fuel(){ + int fuel = max - tank; + while(!GazStation.getState().column1.getFuel(this, fuel)){ + try {Thread.sleep(2000);} catch (InterruptedException ex) {} + } + } +} diff --git a/java/samples/multithread/GazStation2/src/gazstation2/FilingColumn.java b/java/samples/multithread/GazStation2/src/gazstation2/FilingColumn.java new file mode 100644 index 0000000..80c2f39 --- /dev/null +++ b/java/samples/multithread/GazStation2/src/gazstation2/FilingColumn.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gazstation2; + +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +class FilingColumn { + + private int bigTank; + private volatile boolean isOpen; + + public FilingColumn (){ + bigTank = new Random().nextInt(500); + isOpen = true; + } + + public int getBigTank() { + return bigTank; + } + + public synchronized boolean getFuel(Car car, int fuel) { + if(isOpen){ + if(bigTank + + + + + + + + + + Builds, tests, and runs the project MultithreadingExample. + + + diff --git a/java/samples/multithread/MultithreadingExample/build/classes/.netbeans_automatic_build b/java/samples/multithread/MultithreadingExample/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/MultithreadingExample/build/classes/.netbeans_update_resources b/java/samples/multithread/MultithreadingExample/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/Bank.class b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/Bank.class new file mode 100644 index 0000000..e2339a3 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/Bank.class differ diff --git a/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankAccount.class b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankAccount.class new file mode 100644 index 0000000..af2b435 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankAccount.class differ diff --git a/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankOperation.class b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankOperation.class new file mode 100644 index 0000000..69f3e55 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/BankOperation.class differ diff --git a/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MainClass.class b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MainClass.class new file mode 100644 index 0000000..f0fcba0 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MainClass.class differ diff --git a/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MyThread.class b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MyThread.class new file mode 100644 index 0000000..64d1823 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample/build/classes/multithreadingexample/MyThread.class differ diff --git a/java/samples/multithread/MultithreadingExample/manifest.mf b/java/samples/multithread/MultithreadingExample/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/java/samples/multithread/MultithreadingExample/nbproject/build-impl.xml b/java/samples/multithread/MultithreadingExample/nbproject/build-impl.xml new file mode 100644 index 0000000..78a50db --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/java/samples/multithread/MultithreadingExample/nbproject/genfiles.properties b/java/samples/multithread/MultithreadingExample/nbproject/genfiles.properties new file mode 100644 index 0000000..cb81046 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=87dec22c +build.xml.script.CRC32=3cf2961a +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=87dec22c +nbproject/build-impl.xml.script.CRC32=5ad5c371 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/java/samples/multithread/MultithreadingExample/nbproject/private/private.properties b/java/samples/multithread/MultithreadingExample/nbproject/private/private.properties new file mode 100644 index 0000000..11ff3b8 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/java/samples/multithread/MultithreadingExample/nbproject/private/private.xml b/java/samples/multithread/MultithreadingExample/nbproject/private/private.xml new file mode 100644 index 0000000..1b83c49 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/MultithreadingExample/src/multithreadingexample/BankOperation.java + + + diff --git a/java/samples/multithread/MultithreadingExample/nbproject/project.properties b/java/samples/multithread/MultithreadingExample/nbproject/project.properties new file mode 100644 index 0000000..99b7f0f --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/project.properties @@ -0,0 +1,74 @@ +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} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MultithreadingExample.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=multithreadingexample.MainClass +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/java/samples/multithread/MultithreadingExample/nbproject/project.xml b/java/samples/multithread/MultithreadingExample/nbproject/project.xml new file mode 100644 index 0000000..62686c4 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + MultithreadingExample + + + + + + + + + diff --git a/java/samples/multithread/MultithreadingExample/src/multithreadingexample/Bank.java b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/Bank.java new file mode 100644 index 0000000..fd50d10 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/Bank.java @@ -0,0 +1,19 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author denis + */ +public class Bank { + public static List accounts = new ArrayList<>(); +} diff --git a/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankAccount.java b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankAccount.java new file mode 100644 index 0000000..992eacd --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankAccount.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample; + +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class BankAccount { + private int number; + private int fund; + + public BankAccount(int fund) { + this.number = new Random().nextInt(1000000); + this.fund = fund; + } + + public int getFund() { + return fund; + } + + public int fundUp(int summ){ + int fund = this.fund; + try {Thread.sleep(1000);} catch (InterruptedException ex) {} + fund += summ; + this.fund = fund; + return this.fund; + } + + public int fundDown(int summ){ + int fund = this.fund; + try {Thread.sleep(1000);} catch (InterruptedException ex) {} + fund -= summ; + this.fund = fund; + return this.fund; + } +} diff --git a/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankOperation.java b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankOperation.java new file mode 100644 index 0000000..40ed15c --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/BankOperation.java @@ -0,0 +1,32 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class BankOperation implements Runnable{ + + @Override + public void run() { + BankAccount account = Bank.accounts.get(0); + + synchronized (account){ + String line = "Состояние до: " + account.getFund() + "руб., добавляем 10000 и получаем: " + account.fundUp(10000); + System.out.println(line); + } + + synchronized (account){ + String line = "Состояние до: " + account.getFund() + "руб., убавляем на 10000 и получаем: " + account.fundDown(10000); + System.out.println(line); + } + } + +} diff --git a/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MainClass.java b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MainClass.java new file mode 100644 index 0000000..3f94bb9 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MainClass.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample; + +/** + * + * @author denis + */ +public class MainClass { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + System.out.println("Main thread is started"); + + Bank.accounts.add(new BankAccount(10000)); + + Thread thread1 = new Thread(new BankOperation()); + Thread thread2 = new Thread(new BankOperation()); + Thread thread3 = new Thread(new BankOperation()); + Thread thread4 = new Thread(new BankOperation()); + Thread thread5 = new Thread(new BankOperation()); + Thread thread6 = new Thread(new BankOperation()); + thread1.start(); + thread2.start(); + thread3.start(); + thread4.start(); + thread5.start(); + thread6.start(); + + System.out.println("Mian thread is stoped"); + } + +} diff --git a/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MyThread.java b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MyThread.java new file mode 100644 index 0000000..974f959 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample/src/multithreadingexample/MyThread.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class MyThread extends Thread{ + + @Override + public void run() { + //Thread.sleep(5000); + System.out.println("Привет из параллельного потака 1"); + } + + +} diff --git a/java/samples/multithread/MultithreadingExample_2/build.xml b/java/samples/multithread/MultithreadingExample_2/build.xml new file mode 100644 index 0000000..45caa65 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project MultithreadingExample_2. + + + diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/.netbeans_automatic_build b/java/samples/multithread/MultithreadingExample_2/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/.netbeans_update_resources b/java/samples/multithread/MultithreadingExample_2/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/Bank.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/Bank.class new file mode 100644 index 0000000..f4bbf3b Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/Bank.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankAccount.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankAccount.class new file mode 100644 index 0000000..de2a1fe Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankAccount.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankOperation.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankOperation.class new file mode 100644 index 0000000..aca967a Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/BankOperation.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MultithreadingExample_2.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MultithreadingExample_2.class new file mode 100644 index 0000000..9f82156 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MultithreadingExample_2.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread1.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread1.class new file mode 100644 index 0000000..980d2d2 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread1.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread2.class b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread2.class new file mode 100644 index 0000000..7bddc86 Binary files /dev/null and b/java/samples/multithread/MultithreadingExample_2/build/classes/multithreadingexample_2/MyThread2.class differ diff --git a/java/samples/multithread/MultithreadingExample_2/manifest.mf b/java/samples/multithread/MultithreadingExample_2/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/java/samples/multithread/MultithreadingExample_2/nbproject/build-impl.xml b/java/samples/multithread/MultithreadingExample_2/nbproject/build-impl.xml new file mode 100644 index 0000000..9731ab4 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/java/samples/multithread/MultithreadingExample_2/nbproject/genfiles.properties b/java/samples/multithread/MultithreadingExample_2/nbproject/genfiles.properties new file mode 100644 index 0000000..4564d2a --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=33ff94e6 +build.xml.script.CRC32=c811e3e8 +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=33ff94e6 +nbproject/build-impl.xml.script.CRC32=01054350 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/java/samples/multithread/MultithreadingExample_2/nbproject/private/private.properties b/java/samples/multithread/MultithreadingExample_2/nbproject/private/private.properties new file mode 100644 index 0000000..11ff3b8 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/java/samples/multithread/MultithreadingExample_2/nbproject/project.properties b/java/samples/multithread/MultithreadingExample_2/nbproject/project.properties new file mode 100644 index 0000000..25ce47e --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/nbproject/project.properties @@ -0,0 +1,74 @@ +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} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MultithreadingExample_2.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=multithreadingexample_2.MultithreadingExample_2 +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/java/samples/multithread/MultithreadingExample_2/nbproject/project.xml b/java/samples/multithread/MultithreadingExample_2/nbproject/project.xml new file mode 100644 index 0000000..ec5ae3f --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + MultithreadingExample_2 + + + + + + + + + diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/Bank.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/Bank.java new file mode 100644 index 0000000..05985c1 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/Bank.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author denis + */ +public class Bank { + public static List accounts = new ArrayList<>(); +} diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankAccount.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankAccount.java new file mode 100644 index 0000000..1187005 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankAccount.java @@ -0,0 +1,42 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +import java.util.Random; + +/** + * + * @author denis + */ +public class BankAccount { + private int number; + private int fund; + + public BankAccount(int fund) { + this.number = new Random().nextInt(1000000); + this.fund = fund; + } + + public int getFund() { + return fund; + } + + public synchronized int fundUp(int summ){ + int fund = this.fund; + //try {Thread.sleep(10);} catch (InterruptedException ex) {} + fund += summ; + this.fund = fund; + return this.fund; + } + + public synchronized int fundDown(int summ){ + int fund = this.fund; + //try {Thread.sleep(10);} catch (InterruptedException ex) {} + fund -= summ; + this.fund = fund; + return this.fund; + } +} diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankOperation.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankOperation.java new file mode 100644 index 0000000..a40d225 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/BankOperation.java @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +/** + * + * @author denis + */ +public class BankOperation implements Runnable{ + + public boolean isPlus = true; + + @Override + public void run() { + BankAccount account = Bank.accounts.get(0); + + synchronized (account){ + if(isPlus){ + String line1 = "Состояние до: " + account.getFund() + "руб., добавляем 10000 и получаем: " + account.fundUp(10000); + System.out.println(line1); + }else{ + String line2 = "Состояние до: " + account.getFund() + "руб., убавляем на 10000 и получаем: " + account.fundDown(10000); + System.out.println(line2); + } + } + } +} diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MultithreadingExample_2.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MultithreadingExample_2.java new file mode 100644 index 0000000..fc519e0 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MultithreadingExample_2.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +/** + * + * @author denis + */ +public class MultithreadingExample_2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + System.out.println("Main thread start"); +// MyThread1 thread1 = new MyThread1(); +// Thread thread = new Thread(thread1); +// thread.start(); +// +// MyThread2 thread2 = new MyThread2(); +// thread2.start(); + + + Bank.accounts.add(new BankAccount(10000)); + BankOperation operation1 = new BankOperation(); + operation1.isPlus = false; + BankOperation operation2 = new BankOperation(); + BankOperation operation3 = new BankOperation(); + operation3.isPlus = false; + BankOperation operation4 = new BankOperation(); + BankOperation operation5 = new BankOperation(); + operation5.isPlus = false; + BankOperation operation6 = new BankOperation(); + for(int i=0 ; i<50 ; i++){ + new Thread(operation1).start(); + new Thread(operation2).start(); + new Thread(operation3).start(); + new Thread(operation4).start(); + new Thread(operation5).start(); + new Thread(operation6).start(); + } + + System.out.println("Main thread finish"); + } + +} diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread1.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread1.java new file mode 100644 index 0000000..d432019 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread1.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author denis + */ +public class MyThread1 implements Runnable{ + + @Override + public void run() { + try { + Thread.sleep(500); + System.out.println("Thread1 start"); + } catch (InterruptedException ex) { + Logger.getLogger(MyThread1.class.getName()).log(Level.SEVERE, null, ex); + } + } + +} diff --git a/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread2.java b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread2.java new file mode 100644 index 0000000..e1ff087 --- /dev/null +++ b/java/samples/multithread/MultithreadingExample_2/src/multithreadingexample_2/MyThread2.java @@ -0,0 +1,19 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package multithreadingexample_2; + +/** + * + * @author denis + */ +public class MyThread2 extends Thread{ + + @Override + public void run() { + System.out.println("Thread2 start"); + } + +}