File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class ThreadPriorityExample {
2
+
3
+ public static void main (String [] args ) {
4
+ Thread thread1 = new Thread (() -> {
5
+ System .out .println ("Thread 1 with priority " + Thread .MAX_PRIORITY + " is running..." );
6
+ try {
7
+ Thread .sleep (1000 );
8
+ } catch (InterruptedException e ) {
9
+ e .printStackTrace ();
10
+ }
11
+ });
12
+ thread1 .setPriority (Thread .MAX_PRIORITY );
13
+
14
+ Thread thread2 = new Thread (() -> {
15
+ System .out .println ("Thread 2 with priority " + Thread .MAX_PRIORITY + " is running..." );
16
+ try {
17
+ Thread .sleep (1000 );
18
+ } catch (InterruptedException e ) {
19
+ e .printStackTrace ();
20
+ }
21
+ });
22
+ thread2 .setPriority (Thread .MAX_PRIORITY );
23
+
24
+ Thread thread3 = new Thread (() -> {
25
+ System .out .println ("Thread 3 with priority " + Thread .NORM_PRIORITY + " is running..." );
26
+ });
27
+ thread3 .setPriority (Thread .NORM_PRIORITY );
28
+
29
+ Thread thread4 = new Thread (() -> {
30
+ System .out .println ("Thread 4 with priority " + Thread .NORM_PRIORITY + " is running..." );
31
+ });
32
+ thread4 .setPriority (Thread .NORM_PRIORITY );
33
+
34
+ Thread thread5 = new Thread (() -> {
35
+ System .out .println ("Thread 5 with priority " + Thread .MIN_PRIORITY + " is running..." );
36
+ });
37
+ thread5 .setPriority (Thread .MIN_PRIORITY );
38
+
39
+ thread1 .start ();
40
+ thread2 .start ();
41
+ thread3 .start ();
42
+ thread4 .start ();
43
+ thread5 .start ();
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments