-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadsuse.java
More file actions
63 lines (61 loc) · 1.52 KB
/
Threadsuse.java
File metadata and controls
63 lines (61 loc) · 1.52 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
class Thread1 implements Runnable {
Thread t;
Thread1(){
t = new Thread(this,"DemoThread1");
System.out.println("Child Thread1 :"+t);
t.start();
}
public void run(){
try{
for(int i=1;i<=3;i++){
System.out.println("Child Thread1 :BMS College of Engineering");
Thread.sleep(10000);
}
}
catch(InterruptedException ie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Child1 Thread");
}
}
}
class Thread2 extends Thread{
Thread2(){
super("Thread2");
System.out.println("Child Thread2 :"+this);
start();
}
public void run(){
try{
for(int i=1;i<=5;i++){
System.out.println("Child Thread2 :CSE");
sleep(2000);
}
}
catch(InterruptedException ie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Child2 Thread");
}
}
}
public class Threadsuse {
public static void main(String[] args){
Thread1 t1=new Thread1();
Thread2 t2=new Thread2();
try{
for(int i=1;i<=18;i++){
System.out.println("Main Thread :"+i);
Thread.sleep(2500);
}
}
catch(InterruptedException ie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Main Thread");
}
}
}