Facebook
From me, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 118
  1. package Task3;
  2.  
  3.  
  4. class NewThread implements Runnable{
  5.     String name;
  6.     Thread t;
  7.     NewThread(String threadName)
  8.     {
  9.         name = threadName;
  10.         t = new Thread(this,name);
  11.         System.out.println("New Thread: "+ t);
  12.         t.start();
  13. }   @Override
  14.     public void run() {
  15.         for(int i =0; i<=5; i++){
  16.             System.out.println(name +": "+ i);
  17.             try {
  18.                 Thread.sleep(1000);
  19.             } catch (InterruptedException e) {
  20.                 throw new RuntimeException(e);
  21.             }
  22.         }
  23.         System.out.println(name + ": existing.");
  24.  
  25.     }
  26. }
  27. public class task3 {
  28.     public static void main(String[] args) {
  29.         NewThread ob1 =new NewThread("One");
  30.         NewThread ob2 =new NewThread("Two");
  31.         NewThread ob3 =new NewThread("Three");
  32.         System.out.println("Thread One isw Alive: " + ob1.t.isAlive());
  33.         System.out.println("Thread One isw Alive: " + ob2.t.isAlive());
  34.         System.out.println("Thread One isw Alive: " + ob3.t.isAlive());
  35.     }
  36. }
  37.