-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadDemo11.java
51 lines (41 loc) · 1.14 KB
/
ThreadDemo11.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
46
47
48
49
50
51
class Demo extends Thread
{
public void run()
{
int i = 0;
for(i = 1; i<= 10; i++)
{
try
{
System.out.println(Thread.currentThread().getName()+" : "+i);
Thread.sleep(500);
}
catch(InterruptedException obj)
{}
}
}
}
class ThreadDemo11
{
public static void main(String A[]) throws InterruptedException
{
System.out.println("Inside main thread");
Demo obj1 = new Demo();
Demo obj2 = new Demo();
Thread t1 = new Thread(obj1);
Thread t2 = new Thread(obj2);
t1.setName("First");
t2.setName("Second");
System.out.println("Priority of t1 is : "+t1.getPriority());
System.out.println("Priority of t2 is : "+t2.getPriority());
t1.setPriority(10);
t2.setPriority(2);
System.out.println("Priority of t1 is : "+t1.getPriority());
System.out.println("Priority of t2 is : "+t2.getPriority());
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println("End of main thread");
}
}