forked from Java2ArkTS/Java2ArkTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyn.java
More file actions
28 lines (27 loc) · 679 Bytes
/
Copy pathSyn.java
File metadata and controls
28 lines (27 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class TestThread implements Runnable {
private int tickets = 10000;
public void run() {
while (true) {
sale();
}
}
public synchronized void sale() {
if (tickets > 0) {
if (tickets % 100 == 0)
System.out.println("is sailing ticket" + tickets);
tickets = tickets-1;
}
}
public int sum(int a, int b) {
return a + b;
}
}
public class Syn {
public static void main(String[] args) {
TestThread tt = new TestThread();
new Thread(tt).start();
new Thread(tt).start();
new Thread(tt).start();
new Thread(tt).start();
}
}