Multithreading Programs

 ThreadD class:-

class ThreadD extends Thread{

 public void run(){


   System.out.println("run()");

  }


 public static void main(String[] args){

   

   ThreadD t = new ThreadD();

   t.start();


  }


}

ThreadInterface:- 


class Demo{

void show(){

  System.out.println("show()");

 }

}


interface I1{

 void disp();

}

class ThreadInter extends Demo implements Runnable,I1{


 public void run(){

  

   System.out.println("run()");

  }

 public void disp(){

  

   System.out.println("disp()");

  }

 public static void main(String[] args){

   

   ThreadInter obj = new ThreadInter();

   Thread t = new Thread(obj);

   t.start();


    obj.show();

    obj.disp();

 }

}


ThreadFun :-

 class ThreadFun extends Thread{

   

  public void run(){

   //System.out.println(getPriority()+"   "+isAlive());


 for(int i=0;i<5;i++){

    System.out.println(getName());


    try{ 

   Thread.sleep(1000);

}

   catch(Exception e){

    System.out.println(e);

   }   

}

 




 }


  public static void main(String[] args){

   

   System.out.println(Thread.currentThread().getPriority());

   

   ThreadFun t = new ThreadFun();

   t.setName("java");

   t.start();

   t.setPriority(10);

   ThreadFun t1 = new ThreadFun();

   t1.start();


   

}

}

Post a Comment

0 Comments