forked from disha2sinha/Object-Oriented-Programming-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultithreading2.java
46 lines (43 loc) · 1.02 KB
/
Multithreading2.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
package Multithreading;
/**
* Multithreading2
*/
class DemoThread extends Thread {
DemoThread()
{
super("Demo Thread");
System.out.println("Child Thread:"+this);
start();
}
public void run() {
try{
for(int i=8;i>0;i--)
{
System.out.println("Child:"+i);
Thread.sleep(500);
}
}
catch(InterruptedException e)
{
System.out.println("Child Interrupted");
}
System.out.println("Child Exiting");
}
}
class Multithreading2 {
public static void main(String[] args) {
new DemoThread();
try{
for(int i=5;i>0;i--)
{
System.out.println("Main:"+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Main Interrupted");
}
System.out.println("Main Exiting");
}
}