We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 104bc5d commit 2914172Copy full SHA for 2914172
src/chapter4/AtomicIntegerDemo.java
@@ -0,0 +1,36 @@
1
+package chapter4;
2
+
3
+import java.util.concurrent.atomic.AtomicInteger;
4
5
6
+public class AtomicIntegerDemo {
7
+ static AtomicInteger i = new AtomicInteger();
8
9
+ public static class AddThread implements Runnable {
10
11
+ @Override
12
+ public void run() {
13
+ for (int j = 0; j < 10002; j++) {
14
+ i.incrementAndGet();
15
+ }
16
17
18
19
+ public static void main(String args[]) throws InterruptedException {
20
21
+ Thread[] threads = new Thread[10];
22
23
+ for (int j = 0; j < 10; j++) {
24
+ threads[j] = new Thread(new AddThread());
25
26
27
28
+ threads[j].start();
29
30
31
+ threads[j].join();
32
33
34
+ System.out.println(i);
35
36
+}
0 commit comments