aboutsummaryrefslogtreecommitdiff
path: root/parallel/Atomic.java
diff options
context:
space:
mode:
authortoni <toni@devlap.local>2015-11-30 09:56:57 +0100
committertoni <toni@devlap.local>2015-11-30 11:08:11 +0100
commit7197dcc620d71f052d4114d7419132b8c0204178 (patch)
tree5de247a408a42d2a5c5e57af3e60a16ac7947480 /parallel/Atomic.java
parent0c7a4259f5d34a332886c9a62ed223784242ade7 (diff)
added multithreading sync/memory examples
Diffstat (limited to 'parallel/Atomic.java')
-rw-r--r--parallel/Atomic.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/parallel/Atomic.java b/parallel/Atomic.java
new file mode 100644
index 0000000..d091e0a
--- /dev/null
+++ b/parallel/Atomic.java
@@ -0,0 +1,18 @@
+public class Main {
+
+ public static volatile boolean running = true;
+ public static int cnt = 0;
+
+public static void main(String[] args) throws InterruptedException {
+ System.out.println("start");
+ Thread t = new Thread( () -> { System.out.println("Ich bin ein Thread"); while (running) { cnt++; }; } );
+ t.start();
+ Thread.sleep(1000);
+ running = false;
+ t.join();
+ System.out.println("ende");
+ System.out.println("ausgefuhrt: " + cnt);
+ System.err.println(cnt);
+}
+
+}