Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

package chin;

import java.util.*;
public class Chin extends Thread
{
public static void main(String[]args){
Chin thread1 = new Chin();
Chin thread2 = new Chin();
Scanner input = new Scanner (System.in);
String keys,keys1;
System.out.print("Name your first thread: ");
String userName = input.nextLine();
System.out.print("Name your second thread:");
String userName1 = input.nextLine();
thread1.setName("Task A is");
thread2.setName ("Task B is");

thread1.getName();

thread2.getName();

System.out.println(thread1.getName() + " " + thread1.getState());


System.out.println(thread2.getName() + " " + thread2.getState());
System.out.println(" ");
System.out.println(" Starting the threads.... ");

thread1.start();
thread2.start();

try {
Thread.sleep(500);
Thread.sleep(500);
System.out.println(" ");
System.out.println(" after sleep ");

System.out.println(thread1.getName() + " " + Thread.State.TERMINATED);


System.out.println(thread2.getName() + " " + Thread.State.TERMINATED);
}
catch(InterruptedException e){
System.out.println(Thread.State.TERMINATED);
}
}
public void run(){
System.out.println(Thread.currentThread().getName()+ " RUNNABLE ");
}
}

You might also like