-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadDemo4.java
More file actions
42 lines (42 loc) · 855 Bytes
/
ThreadDemo4.java
File metadata and controls
42 lines (42 loc) · 855 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
package Multi_Threading;
class A extends Thread
{
Thread t = new Thread("A");
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println("Value of "+t+" "+i);
try { Thread.sleep(1000); }catch(InterruptedException e) { }
}
System.out.println("Class A is exited!");
}
}
class B extends Thread
{
Thread t = new Thread("B");
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println("Value of "+t+" "+i);
try { Thread.sleep(1000); }catch(InterruptedException e) { }
}
System.out.println("class B is exited!");
}
}
public class ThreadDemo4 {
public static void main(String[] args)
{
A t1 = new A();
B t2 = new B();
t1.start();
t2.start();
try
{
t1.join();
t2.join();
}catch(InterruptedException e){}
System.out.println("Main Class Exited!");
}
}