We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1819261 commit d4f3666Copy full SHA for d4f3666
1 file changed
02nio/nio02/src/main/java/thread/github/pxd/ThreadABCPrint.java
@@ -0,0 +1,44 @@
1
+package thread.github.pxd;
2
+
3
+public class ThreadABCPrint {
4
5
+ volatile static int completeThread = 0;
6
7
+ public static void main(String[] args) {
8
9
+ Thread thread1 = new Thread(() -> {
10
+ while (true){
11
12
+ if (completeThread == 3 || completeThread == 0) {
13
+ System.out.print("A");
14
+ completeThread = 1;
15
+ }
16
17
+ });
18
19
+ Thread thread2 = new Thread(() -> {
20
21
22
+ if (completeThread == 1) {
23
+ System.out.print("B");
24
+ completeThread = 2;
25
26
27
28
29
+ Thread thread3 = new Thread(() -> {
30
31
32
+ if (completeThread == 2) {
33
+ System.out.print("C");
34
+ completeThread = 3;
35
36
37
38
39
+ thread1.start();
40
+ thread2.start();
41
+ thread3.start();
42
43
44
+}
0 commit comments