-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadmain.java
More file actions
56 lines (47 loc) · 1003 Bytes
/
Copy pathThreadmain.java
File metadata and controls
56 lines (47 loc) · 1003 Bytes
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
package Day15;
class A extends Thread{
@Override
public void run(){
for(int i=2;i<=20;i=i+2){
System.out.println("Even No : "+i);
try{
Thread.sleep(100);
}catch(Exception e){
System.out.println(e);
}
}
}
}
class B extends Thread{
@Override
public void run(){
for(int i=1;i<=20;i=i+2){
System.out.println("Odd : "+i);
try{
Thread.sleep(100);
}catch(Exception e){
System.out.println(e);
}
}
}
}
public class Threadmain {
public static void main(String[] args){
A thread1 = new A();
B thread2 = new B();
thread1.setName("Th1");
thread2.setName("Th2");
System.out.println(thread1.getName());
System.out.println(thread2.getName());
thread1.start();
System.out.println(thread1.isAlive());
try{
thread1.join();
}catch(Exception e){
System.out.println(e);
}
System.out.println(thread1.isAlive());
thread2.start();
System.out.println("Printed");
}
}