The Java Program: SimpleRun.java
1 // SimpleRun.java -- illustrate thread creation via Runnable
2
3 class Action implements Runnable {
4 public void run() {
5 Thread t = Thread.currentThread();
6 for (int i = 0; i < 10; i++) {
7 System.out.println (i + " " + t.getName());
8 try {
9 t.sleep((int)(Math.random() * 1000));
10 } catch (InterruptedException e) {
11 // do nothing!
12 }
13 }
14 System.out.println ("DONE! " + t.getName());
15 }
16 }
17
18 class SimpleRun {
19 public static void main (String args[]) {
20 new Thread(new Action(), "Jamaica").start();
21 new Thread(new Action(), "Bahamas").start();
22 }
23 }