-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadDemo6.java
52 lines (42 loc) · 1016 Bytes
/
ThreadDemo6.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
49
50
51
52
class Demo extends Thread
{
public void run()
{
int i = 0;
for(i = 1; i <= 10; i++)
{
try
{
System.out.println(Thread.currentThread().getName()+" : "+i);
Thread.sleep(1000);
}
catch(InterruptedException obj)
{
}
}
}
}
class ThreadDemo6
{
public static void main(String Arg[])
{
System.out.println("Inside Main method");
Demo obj1 = new Demo();
Demo obj2 = new Demo();
Thread t1 = new Thread(obj1);
Thread t2 = new Thread(obj2);
t1.setName("first Thread");
t2.setName("second Thread");
t1.start();
t2.start();
try
{
t1.join();
t2.join();
}
catch(InterruptedException obj)
{
}
System.out.println("End of main thread");
}
}