diff options
Diffstat (limited to 'parallel/Atomic.java')
-rw-r--r-- | parallel/Atomic.java | 18 |
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); +} + +} |