- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample2.java
More file actions
Latest commit
45 lines (45 loc) · 1018 Bytes
/
Copy pathexample2.java
File metadata and controls
45 lines (45 loc) · 1018 Bytes
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
classCountextendsThread
{
Count()
{
super("my extending thread");
System.out.println("my thread created" + this);
start();
}
publicvoidrun()
{
try
{
for (inti=0 ;i<100;i++)
{
System.out.println("Printing the count " + i);
Thread.sleep(1000);
}
}
catch(InterruptedExceptione)
{
System.out.println("my thread interrupted");
}
System.out.println("My thread run is over" );
}
}
classExtendingExample
{
publicstaticvoidmain(Stringargs[])
{
Countcnt = newCount();
try
{
while(cnt.isAlive())
{
System.out.println("Main thread will be alive till the child thread is live");
Thread.sleep(1500);
}
}
catch(InterruptedExceptione)
{
System.out.println("Main thread interrupted");
}
System.out.println("Main thread's run is over" );
}
}