-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPrior.java
More file actions
43 lines (40 loc) · 1.16 KB
/
Copy pathThreadPrior.java
File metadata and controls
43 lines (40 loc) · 1.16 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
/*
* getName() - It is used to get the name of the Thread
* setName() - It is used to set the new name of the Thread
* getPriority() - Gives the current Priority
* setPriority() - Set the new Priority value
*/
public class ThreadPrior
{
public static void main(String[] args)
{
Thread t1 = new Thread (() ->
{
for(int i=1;i<=5;i++)
{
System.out.println("Hi");
try { Thread.sleep(500);}catch(Exception e) {}
}
}, "Hai Thread"); //Giving the name of Thread
Thread t2 = new Thread(() ->
{
for(int i=1;i<=5;i++)
{
System.out.println("Hello");
try {Thread.sleep(500);}catch(Exception e) {}
}
}, "Hello Thread");
System.out.println(t1.getName()); //prints Hai Thread . def Thread-0
t1.setName("First Thread"); //Another way of giving name of the Thread
System.out.println(t1.getName()); //prints First Thread
t1.setPriority(Thread.MIN_PRIORITY); //or we can give any number(1)
t2.setPriority(Thread.MAX_PRIORITY); // or we can give any number(10)
System.out.println(t1.getPriority());
System.out.println(t2.getPriority());
t1.start();
{
try {Thread.sleep(10);}catch(Exception e) {}
}
t2.start();
}
}