forked from disha2sinha/Object-Oriented-Programming-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultithreading3.java
42 lines (37 loc) · 1 KB
/
Multithreading3.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
package Multithreading;
/**
* Multithreading2
*/
class DemoThread implements Runnable {
Thread t;
DemoThread() {
t=new Thread(this,"Demo Thread");
System.out.println("Child Thread:" + t);
t.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 Multithreading3 {
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");
}
}