MultiTasking Using Thread,
class MyThread implements Runnable
{
String str;
MyThread(String str)
{
this.str=str;
}
public void run()
{
for(int i=1;i<=10; i++)
{
System.out.println(str+":"+i);
try{
Thread.sleep(2000);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}
}
class Main
{
public static void main(String args[])
{
MyThread mt1=new MyThread("Cut the ticket");
MyThread mt2=new MyThread("show the Seat");
Thread t1=new Thread(mt1);
Thread t2=new Thread(mt2);
t1.start();
t2.start();
}
}
class MyThread implements Runnable
{
String str;
MyThread(String str)
{
this.str=str;
}
public void run()
{
for(int i=1;i<=10; i++)
{
System.out.println(str+":"+i);
try{
Thread.sleep(2000);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}
}
class Main
{
public static void main(String args[])
{
MyThread mt1=new MyThread("Cut the ticket");
MyThread mt2=new MyThread("show the Seat");
Thread t1=new Thread(mt1);
Thread t2=new Thread(mt2);
t1.start();
t2.start();
}
}
0 comments:
Post a Comment