-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadDemo1.java
48 lines (47 loc) · 1.24 KB
/
ThreadDemo1.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
47
48
class ThreadDemo1_1 extends Thread
{
ThreadDemo1_1(String a, ThreadGroup b)
{
super(b, a);
}
public void run()
{
for (int i = 0; i< 10; i++)
{
try
{
Thread.sleep(10);
}
catch (InterruptedException ex)
{
System.out.println(Thread.currentThread()
.getName());
}
}
System.out.println(Thread.currentThread()
.getName());
}
}
public class ThreadDemo1
{
public static void main(String arg[]) throws
InterruptedException, SecurityException
{
ThreadGroup obj1 = new ThreadGroup("Parent
thread =====> ");
ThreadGroup obj2 = new ThreadGroup(obj1,
"child thread =====> ");
ThreadDemo1_1 t1 = new ThreadDemo1_1("*******
Thread-1*******", obj1);
t1.start();
ThreadDemo1_1 t2 = new ThreadDemo1_1("*******
Thread-2*******", obj1);
t2.start();
obj1.checkAccess();
System.out.println(obj1.getName() + " has
access");
obj2.checkAccess();
System.out.println(obj2.getName() + " has
access");
}
}