-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread8.java
More file actions
36 lines (30 loc) · 1.08 KB
/
Copy pathThread8.java
File metadata and controls
36 lines (30 loc) · 1.08 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
import java.lang.*;
class ThreadNew extends Thread {
ThreadNew(String name, ThreadGroup tgrp) {
super(tgrp, name);
start();
}
public void run() {
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(5);
} catch (InterruptedException e) {
System.out.println(e);
}
}
System.out.println(Thread.currentThread().getName() + " is finished.");
}
}
public class Thread8 {
public static void main(String args[]) {
ThreadGroup tg = new ThreadGroup("The parent group");
ThreadGroup tg1 = new ThreadGroup(tg, "the child group");
ThreadNew t1 = new ThreadNew("first", tg);
System.out.println("starting the first");
ThreadNew t2 = new ThreadNew("second", tg);
System.out.println("Starting the second");
System.out.println("The parent of " + tg.getName() + " is " + tg.getParent().getName());
System.out.println("The parent of " + tg1.getName() + " is " + tg1.getParent().getName());
tg.interrupt();
}
}