-
Notifications
You must be signed in to change notification settings - Fork 0
/
j56JoinInThread.java
58 lines (51 loc) · 1.53 KB
/
j56JoinInThread.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
class ex_set_thread_priority1 extends Thread{
public ex_set_thread_priority1(String name){
// Constructor in ex_set_thread_priority class
super(name);
}
@Override
public void run(){
int i = 0;
while (i < 40){
// return Thread Name
System.out.println("Thread1 Myame is : "+this.getName());
i++;
}
}
}
class ex_set_thread_priority2 extends Thread{
public ex_set_thread_priority2(String name){
// Constructor in ex_set_thread_priority class
super(name);
}
@Override
public void run(){
int i = 0;
while (i < 20){
// return Thread Name
System.out.println("On I = "+i);
i++;
}
}
}
public class j56JoinInThread {
public static void main(String[] args){
ex_set_thread_priority1 ESTP1 = new ex_set_thread_priority1("Thread1");
ex_set_thread_priority2 ESTP2 = new ex_set_thread_priority2("Thread2");
/*
Join Metheod
- if you want to run only one thread in any situation and stoip other thread
we use joi metheod
- join metheod always use in try block b/c if the Thread previously kill then this block makes an Error
*/
// ESTP1.start();
ESTP2.start();
try {
ESTP2.join();
}
catch (Exception e) {
System.out.println(e);
}
ESTP1.start();
}
}