Creating a class that implements Runnable - Java Thread

Java examples for Thread:Thread Operation

Description

Creating a class that implements Runnable

Demo Code

class LaunchEvent implements Runnable {
  private int start;
  private String message;

  public LaunchEvent(int start, String message) {
    this.start = start;
    this.message = message;
  }// w  w  w .j a  va2  s .  c o  m

  public void run() {
    try {
      Thread.sleep(20000 - (start * 1000));
    } catch (InterruptedException e) {
    }
    System.out.println(message);
  }
}

public class Main {
  public static void main(String[] args) {

    Runnable flood, ignition, liftoff;
    flood = new LaunchEvent(16, "A");
    ignition = new LaunchEvent(6, "B");
    liftoff = new LaunchEvent(0, "C");

    new Thread(flood).start();
    new Thread(ignition).start();
    new Thread(liftoff).start();
  }
}

Related Tutorials