-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestroyExample.java
More file actions
63 lines (51 loc) · 1.35 KB
/
Copy pathDestroyExample.java
File metadata and controls
63 lines (51 loc) · 1.35 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
package Threading;
// import statement
import java.lang.*;
class ThreadNew extends Thread
{
// constructor of the class
ThreadNew(String tName, ThreadGroup tgrp)
{
super(tgrp, tName);
start();
}
// overriding the run() method
public void run()
{
for (int j = 0; j < 100; j++)
{
try
{
Thread.sleep(5);
}
catch (InterruptedException e)
{
System.out.println("The exception has been encountered " + e);
}
}
System.out.println(Thread.currentThread().getName() + " thread has finished executing");
}
}
public class DestroyExample
{
// main method
public static void main(String argvs[]) throws SecurityException, InterruptedException
{
// creating the thread group
ThreadGroup tg = new ThreadGroup("the parent group");
ThreadGroup tg1 = new ThreadGroup(tg, "the child group");
ThreadNew th1 = new ThreadNew("the first", tg);
System.out.println("Starting the first");
ThreadNew th2 = new ThreadNew("the second", tg);
System.out.println("Starting the second");
// waiting until the other threads has been finished
th1.join();
th2.join();
// destroying the child thread group
tg1.destroy();
System.out.println(tg1.getName() + " is destroyed.");
// destroying the parent thread group
tg.destroy();
System.out.println(tg.getName() + " is destroyed.");
}
}