public class CurrentThreadName1 extends Thread {
@Override
public void run() {
//setting name of thread
Thread.currentThread().setName("User Created Thread");
//getting name of thread with a msg
System.out.println("thread running : " + Thread.currentThread().getName());
}
public static void main(String[] args) {
System.out.println("hello : " + Thread.currentThread().getName());
CurrentThreadName1 ct = new CurrentThreadName1();
//thread name can be at both place i.e
//here i.e in main method
//in run method
// ct.setName("JavaInvent");
ct.start();
//checking if current thread(i.e main thread) is alive or not
System.out.println(
Thread.currentThread().getName() + ":" + Thread.currentThread().isAlive()
);
//checking if user created thread is alive or not
System.out.println(ct.getName() + ":" + ct.isAlive());
}
}