Aim:- Write a program to
implement multi-threading in java.
import java.lang.*;
class NewThread extends Thread
{
String str;
NewThread(String name)
{
super(name);
str=name;
System.out.println(name +this);
start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.println(str +": " +i);
sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Chlid
interrupted ");
}
System.out.println("Exiting "
+str +" thread ");
}
}
class MultiThread
{
public static void main(String args[])
{
NewThread one=new
NewThread("One");
NewThread two=new NewThread("Two");
}
}
Output:-
No comments:
Post a Comment