/* From the James Gosling java book. Like class String, class Thread does not need to be imported. It is built into the language. */ public class ThreadDemo { public static void main(String[] args) { MyThread mythread1 = new MyThread("hello", 3); mythread1.start(); MyThread mythread2 = new MyThread("goodbye", 6); mythread2.start(); } } class MyThread extends Thread { private String string; private int seconds; public MyThread(String string, int seconds) { this.string = string; this.seconds = seconds; } @Override public void run() { try { for (;;) { //infinite loop System.out.println(string + " "); Thread.sleep(seconds * 1000); } } catch (InterruptedException e) { System.err.println(e); e.printStackTrace(); } } }