Practical 14


Aim:- Write a program to implement multi-threading in java.

JAVA Code :-

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

Programs

Home Aim:- Write a program to convert rupees to dollar. (60rupees=1 dollar). Aim:- Write a program that calculate percentage marks...