forked from Java2ArkTS/Java2ArkTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityDemo.java
More file actions
40 lines (37 loc) · 1.04 KB
/
Copy pathPriorityDemo.java
File metadata and controls
40 lines (37 loc) · 1.04 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
public class PriorityDemo {
public static int count = 0;
public static void main(String args[]) {
Thread high = new HightPriority();
Thread low = new LowPriority();
high.setPriority(Thread.MAX_PRIORITY);
low.setPriority(Thread.MIN_PRIORITY);
low.start();
high.start();
}
}
class HightPriority extends Thread {
public void run() {
while (true) {
synchronized (PriorityDemo.class) {
PriorityDemo.count++;
if (PriorityDemo.count > 1000000) {
System.out.println("HightPriority is complete!");
break;
}
}
}
}
}
class LowPriority extends Thread {
public void run() {
while (true) {
synchronized (PriorityDemo.class) {
PriorityDemo.count++;
if (PriorityDemo.count > 1000000) {
System.out.println("LowPriority is complete!");
break;
}
}
}
}
}