Post Views: 4
Write a java program to display name of currently executing Thread in
multithreading.
class CurrentThreadName extends Thread {
public void run() {
// Get currently executing thread
Thread t = Thread.currentThread();
System.out.println("Currently Executing Thread Name: " + t.getName());
}
public static void main(String[] args) {
// Create threads
CurrentThreadName t1 = new CurrentThreadName();
CurrentThreadName t2 = new CurrentThreadName();
CurrentThreadName t3 = new CurrentThreadName();
// Set thread names
t1.setName("Thread-A");
t2.setName("Thread-B");
t3.setName("Thread-C");
// Start threads
t1.start();
t2.start();
t3.start();
}
}