I want to create and start 5 java threads. The threads should display message then stop execution. Am I doing this correctly or not?
public class HelloThread extends Thread {
private String thread_name;
// constructor
HelloThread(String tname) {
thread_name = new String(tname);
}
// override method run()
public void run() {
setName(thread_name);
System.out.println(" Thread " + thread_name); //assigning each thread a name
}
public static void main(String args[]) {
for (int i = 1; i < 6; i++) {
HelloThread mythr_obj = new HelloThread(i + " says Hello World!!! ");
mythr_obj.start(); // start execution of the thread object
}
}
}