Starting a Thread : Thread Starting « Thread « SCJP






class FooRunnable implements Runnable {
   public void run() {
      for(int x = 1; x < 6; x++) {
        System.out.println("Runnable running");
      }
   }
}

public class TestThreads {
   public static void main (String [] args) {
     FooRunnable r = new FooRunnable();
     Thread t = new Thread(r);
     t.start();
   }
}
Runnable running
Runnable running
Runnable running
Runnable running
Runnable running








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