-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path58 Multithreading Thread Priority.txt
More file actions
47 lines (37 loc) · 1021 Bytes
/
58 Multithreading Thread Priority.txt
File metadata and controls
47 lines (37 loc) · 1021 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class ThreadDemo
{
public static void main(String[] args) throws Exception
{
Thread t1 = new Thread(() ->
{
for(int i=1;i<=5;i++)
{
System.out.println("Hi" + " " + Thread.currentThread().getPriority());
try {Thread.sleep(1000); } catch(Exception e){}
}
},"Hi Thread");
Thread t2 = new Thread(() ->
{
for(int i=1;i<=5;i++)
{
System.out.println("Hello");
try {Thread.sleep(1000); } catch(Exception e) {}
}
},"Hello Thread");
// t1.setName("Hi Thread");
// t2.setName("Hello Thread");
// System.out.println(t1.getName());
// System.out.println(t2.getName());
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
System.out.println(t1.getPriority());
System.out.println(t2.getPriority());
t1.start();
try {Thread.sleep(10); } catch(Exception e) {}
t2.start();
t1.join();
t2.join();
System.out.println(t1.isAlive());
System.out.println("Bye");
}
}