-
Notifications
You must be signed in to change notification settings - Fork 0
/
th.java
48 lines (42 loc) · 974 Bytes
/
th.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
import java.util.*;
import java.lang.*;
class myThread1 extends Thread{
@Override
public void run(){
int i=0;
while(i<10){
try{
Thread.sleep(500);
}catch(Exception e){
System.out.println(e);
}
System.out.println("Thread is running\n");
System.out.println("I am happy\n");
i++;
}
}
}
class myThread2 extends Thread{
@Override
public void run(){
int i=0;
while(i<10){
System.out.println("Thread2 is running\n");
System.out.println("I am run\n");
i++;
}
}
}
public class th {
public static void main(String[] args) {
myThread1 t1 = new myThread1();
myThread2 t2 = new myThread2();
t1.start();
try{
t1.join();
}catch(Exception e){
System.out.println(e);
}
t2.start();
}
}