-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.java
More file actions
60 lines (53 loc) · 1.46 KB
/
pack.java
File metadata and controls
60 lines (53 loc) · 1.46 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
package class_programs; // Implementing Runnable
class NewThread implements Runnable
{
// Thread t ; // Student.Swasthik -> t.TObj1 -> t.obj2
// NewThread()
// {
// Thread t = new Thread(this, "Demo Thread");
// System.out.println("Child thread : " + t);
// t.start(); // Start the thread
// }
// This is the entry point for the second thread.
public void run()
{
try
{
for(int i = 5; i > 0; i--)
{
System.out.println("Child Thread: " + i);
Thread.sleep(500);
}
}
catch (InterruptedException e)
{
System.out.println("Child interrupted.");
}
System.out.println("Exiting child thread.");
}
}
class pack
{
public static void main(String args[])
{
NewThread obj = new NewThread(); // create a new child thread
Thread t= new Thread(obj);
// t.start();
// t.setPriority(1);
System.out.println("Child thread : " + t);
t.start();
try
{
for(int i = 5; i > 0; i--)
{
System.out.println("Main Thread: " + i);
Thread.sleep(1000); // main
}
}
catch (InterruptedException e)
{
System.out.println("Main thread interrupted.");
}
System.out.println("Main thread exiting.");
}
}