class MyThread implements Runnable {
public void run() {
try {
System.out.println("Thread ID: " + Thread.currentThread().getId());
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
public class Program {
public static void main(String[] args) {
Thread trd1 = new Thread(new MyThread());
Thread trd2 = new Thread(new MyThread());
Thread trd3 = new Thread(new MyThread());
trd1.setName("Thread_1");
trd2.setName("Thread_2");
trd3.setName("Thread_3");
System.out.println("Thread Name: " + trd1.getName());
System.out.println("Thread Name: " + trd2.getName());
System.out.println("Thread Name: " + trd3.getName());
trd1.start();
trd2.start();
trd3.start();
}
}
/*
run:
Thread Name: Thread_1
Thread Name: Thread_2
Thread Name: Thread_3
Thread ID: 16
Thread ID: 15
Thread ID: 17
*/