Create a Thread method 2: implements Runnable interface : Thread Creation « Thread « SCJP






class DownCounter implements Runnable {
public void run() {
     for (int i = 10; i >= 1; i--) {
       System.out.println("Counting Down: " + i);
     }
   }}

public class MainClass {
  public static void main(String[] argv) {
    DownCounter dc = new DownCounter();
    Thread t = new Thread(dc);
    t.start();
  }
}
Counting Down: 10
Counting Down: 9
Counting Down: 8
Counting Down: 7
Counting Down: 6
Counting Down: 5
Counting Down: 4
Counting Down: 3
Counting Down: 2
Counting Down: 1








7.1.Thread Creation
7.1.1.The simplest way to define code to run in a separate thread is to
7.1.2.A summary of methods used with Threads.
7.1.3.The Life of a Thread
7.1.4.Create Thread method 1: subclass the Thread class and implement the run() method.
7.1.5.Create a Thread method 2: implements Runnable interface
7.1.6.Creating Threads: Subclassing the Thread Class
7.1.7.Creating Thread: Implementing Runnable