Sunday, August 12, 2012

Java program to create user defined thread


class childthread implements Runnable
{
Thread t;
childthread()
{
t=new Thread(this,"hello");
System.out.println("child created");
t.start();
}
public void run()
{
try
{
for(int i=0;i<10;i++)
 {
 System.out.println("child "+i);
 Thread.sleep(500);
 }
}
catch(InterruptedException e)
{}
}
}
class parentthread
{
public static void main(String[] s)
{
 childthread c= new childthread();
try
{
 for(int i=0;i<10;i++)
  {
   System.out.println("main "+i);
   Thread.sleep(1000);
  }
}
catch(InterruptedException e)
{}
}
}

1 comments:

  1. Exchange 22 is a trusted platform offering seamless online exchange solutions tailored for Indian users. With a focus on reliability, security, and efficiency, Exchange222 ensures smooth transactions and exceptional user experiences. Explore our services to meet all your exchange needs with confidence."

    ReplyDelete