- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadsuse.java
More file actions
Latest commit
63 lines (61 loc) · 1.52 KB
/
Copy pathThreadsuse.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
classThread1implementsRunnable {
Threadt;
Thread1(){
t = newThread(this,"DemoThread1");
System.out.println("Child Thread1 :"+t);
t.start();
}
publicvoidrun(){
try{
for(inti=1;i<=3;i++){
System.out.println("Child Thread1 :BMS College of Engineering");
Thread.sleep(10000);
}
}
catch(InterruptedExceptionie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Child1 Thread");
}
}
}
classThread2extendsThread{
Thread2(){
super("Thread2");
System.out.println("Child Thread2 :"+this);
start();
}
publicvoidrun(){
try{
for(inti=1;i<=5;i++){
System.out.println("Child Thread2 :CSE");
sleep(2000);
}
}
catch(InterruptedExceptionie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Child2 Thread");
}
}
}
publicclassThreadsuse {
publicstaticvoidmain(String[] args){
Thread1t1=newThread1();
Thread2t2=newThread2();
try{
for(inti=1;i<=18;i++){
System.out.println("Main Thread :"+i);
Thread.sleep(2500);
}
}
catch(InterruptedExceptionie){
System.out.println(ie);
}
finally{
System.out.println("Exiting Main Thread");
}
}
}