73.multi_threading in java
//multi_threading
class threaA extends Thread
{
public void run()
{
try
{
for (int i = 1; i <= 10; i++ ) {
System.out.println("\t" + i);
Thread.sleep(100);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class threaB extends Thread
{
public void run()
{
try
{
for (int i = 10; i >= 1; i-- ) {
System.out.println("\t" + i);
Thread.sleep(100);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class multi_threading
{
public static void main(String[] args) {
threaA objA = new threaA();
threaB objB = new threaB();
objA.start();
objB.start();
try
{
objA.join();
objB.join();
}
catch(Exception e)
{
System.out.println("Main : " + e);
}
System.out.println("End of main() Program");
}
}
OUTPUT:
1
10
9
2
3
8
4
7
5
6
5
6
4
7
3
8
2
9
10
1
Comments
Post a Comment