-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathThreadPriorityExample.java
45 lines (39 loc) · 1.52 KB
/
ThreadPriorityExample.java
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
41
42
43
44
45
public class ThreadPriorityExample {
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
System.out.println("Thread 1 with priority " + Thread.MAX_PRIORITY + " is running...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
thread1.setPriority(Thread.MAX_PRIORITY);
Thread thread2 = new Thread(() -> {
System.out.println("Thread 2 with priority " + Thread.MAX_PRIORITY + " is running...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
thread2.setPriority(Thread.MAX_PRIORITY);
Thread thread3 = new Thread(() -> {
System.out.println("Thread 3 with priority " + Thread.NORM_PRIORITY + " is running...");
});
thread3.setPriority(Thread.NORM_PRIORITY);
Thread thread4 = new Thread(() -> {
System.out.println("Thread 4 with priority " + Thread.NORM_PRIORITY + " is running...");
});
thread4.setPriority(Thread.NORM_PRIORITY);
Thread thread5 = new Thread(() -> {
System.out.println("Thread 5 with priority " + Thread.MIN_PRIORITY + " is running...");
});
thread5.setPriority(Thread.MIN_PRIORITY);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
}
}