-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.java
61 lines (56 loc) · 1.75 KB
/
Demo.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
52
53
54
55
56
57
58
59
60
61
public class Demo extends Thread {
static Thread t1;
// custom thread
// public void run() {
// for(int i=1; i<=5; i++){
// try{
// Thread.sleep(5000);
// }catch (InterruptedException e){
// e.printStackTrace();
// }
// System.out.println(i);
// }
// }
//
// public static void main(String[] args) {
// Demo d1 = new Demo();
// Demo d2 = new Demo();
//
// d1.start();
// d2.start();
// }
public void run(){
try {
//t1.join();
for (int i = 1; i <=5; i++){
System.out.println("Thread: "+i);
Thread.sleep(1000);
}
}catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException {
t1= Thread.currentThread();
Demo d = new Demo();
Demo d1 = new Demo();
System.out.println("NAME OF THREAD: "+d.getName());
d.setName("Rahulbhai");
System.out.println("change the name: "+d.getName());
System.out.println("the priority of d is: "+d.getPriority());
System.out.println("the priority of d1 is: "+d1.getPriority());
System.out.println(Thread.currentThread().getName());
System.out.println("the priority of main thread is: "+Thread.currentThread().getPriority());
d.start();
d.join();
d1.start();
try {
for(int i = 0 ; i <=5; i++){
System.out.println("main thread: "+i);
Thread.sleep(1000);
}
}catch (Exception e){
e.printStackTrace();
}
}
}