-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadPriority.java
More file actions
49 lines (33 loc) · 1.25 KB
/
Copy pathThreadPriority.java
File metadata and controls
49 lines (33 loc) · 1.25 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
41
42
43
44
45
46
47
48
49
public class ThreadPriority implements Runnable{
@Override
public void run() {
System.out.println("Thread is Running "+Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadPriority tp = new ThreadPriority();
Thread t1 = new Thread(tp,"Thread 1");
Thread t2 = new Thread(tp,"Thread 2");
Thread t3 = new Thread(tp,"Thread 3");
System.out.println("Thread Priority::t1 "+t1.getPriority());
System.out.println("Thread Priority::t2 "+t2.getPriority());
System.out.println("Thread Priority::t3 "+t3.getPriority());
t1.setPriority(3);
t2.setPriority(10);
t3.setPriority(6);
System.out.println("After Thread Priority::t1 "+t1.getPriority());
System.out.println("After Thread Priority::t2 "+t2.getPriority());
System.out.println("After Thread Priority::t3 "+t3.getPriority());
t1.start();
t2.start();
t3.start();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("After Sleep Thread Priority::t1 "+t1.getPriority());
System.out.println("After Sleep Thread Priority::t2 "+t2.getPriority());
System.out.println("After Sleep Thread Priority::t3 "+t3.getPriority());
}
}