-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructor_Thread.java
More file actions
72 lines (60 loc) · 1.87 KB
/
Copy pathConstructor_Thread.java
File metadata and controls
72 lines (60 loc) · 1.87 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package BASICS;
// Thread Constructors: Thread(), Thread(String), Thread(Runnable), Thread(Runnable, String)
/*
class Mythr extends Thread {
public Mythr(String name) {
super(name);
}
public void run() {
int t = 0;
while (t++ < 100)
System.out.println("Harshit");
}
}
*/
class Mythr extends Thread {
public Mythr(String name) {
super(name);
}
public void run() {
int t = 0;
while(true) {
try {
Thread.sleep(455); //pause a Thread for 455m0s
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("This is " + this.getName());
}
}
}
public class Constructor_Thread {
public static void main(String[] args) {
//*************Constructor in Thread****************
// Mythr t1 = new Mythr("Harshit");
// Mythr t2 = new Mythr("Vanshika");
// t1.start();
// t2.start();
// System.out.println("id of the thread is " + t1.getId());
// System.out.println("name of the thread is " + t1.getName());
// //****************Priority Order********************
// Mythr t1 = new Mythr("Harshit1");
// Mythr t2 = new Mythr("Harshit2 (MIN)");
// Mythr t3 = new Mythr("Harshit3");
// Mythr t4 = new Mythr("Harshit4");
// Mythr t5 = new Mythr("Harshit5 (MAX)");
// t5.setPriority(Thread.MAX_PRIORITY);
// t2.setPriority(Thread.MIN_PRIORITY);
// t1.start(); t2.start(); t3.start(); t4.start(); t5.start();
//****************Thread Methods**************
Mythr t1 = new Mythr("Harhsit");
Mythr t2 = new Mythr("MON");
t1.start();
// try{
// t1.join();
// }catch(Exception e){
// System.out.println(e);
// }
t2.start();
}
}