0% found this document useful (0 votes)
8 views1 page

Chin - Java 09 Hands On Activity 1 ARG

The document describes a Java program that creates two thread objects and runs them concurrently. It demonstrates getting and setting thread names, starting the threads, and checking their states.

Uploaded by

asayasmarcjoshua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Chin - Java 09 Hands On Activity 1 ARG

The document describes a Java program that creates two thread objects and runs them concurrently. It demonstrates getting and setting thread names, starting the threads, and checking their states.

Uploaded by

asayasmarcjoshua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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