Instantiates a thread and gives it a name, and then the name is printed out from the run() method : Thread Starting « Thread « SCJP






class NameRunnable implements Runnable {
   public void run() {
       System.out.println("NameRunnable running");
       System.out.println("Run by "
         + Thread.currentThread().getName());
   }
}
public class NameThread {
   public static void main (String [] args) {
     NameRunnable nr = new NameRunnable();
     Thread t = new Thread(nr);
     t.setName("Fred");
     t.start();
   }
}
NameRunnable running
Run by Fred








7.2.Thread Starting
7.2.1.To make a thread execute, you call its start() method.
7.2.2.To start a thread: construct an instance of MyThread and then invoke its start() method
7.2.3.Starting a Thread
7.2.4.Instantiates a thread and gives it a name, and then the name is printed out from the run() method
7.2.5.Starting and Running Multiple Threads