import java.io.*;
public class T1 extends Thread
{
public void run()
{
for(int i=0; i < 5; i++)
{
System.out.println("Child Thread : " + i);
try
{
Thread.sleep(50);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Child thread finished!");
};
public static void main(String[] args) throws IOException
{
Thread t = new Thread(new T1(), "My Thread");
t.start();
for(int i=0; i < 5; i++)
{
System.out.println("Main thread : " + i);
try
{
Thread.sleep(100);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Main thread finished!");
}
}
public class T1 extends Thread
{
public void run()
{
for(int i=0; i < 5; i++)
{
System.out.println("Child Thread : " + i);
try
{
Thread.sleep(50);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Child thread finished!");
};
public static void main(String[] args) throws IOException
{
Thread t = new Thread(new T1(), "My Thread");
t.start();
for(int i=0; i < 5; i++)
{
System.out.println("Main thread : " + i);
try
{
Thread.sleep(100);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Main thread finished!");
}
}
No comments:
Post a Comment