Java tutorial
class TryThread extends Thread { public TryThread(String firstName, String secondName, long delay) { this.firstName = firstName; this.secondName = secondName; aWhile = delay; } public void run() { try { while (true) { System.out.print(firstName); sleep(aWhile); System.out.print(secondName + "\n"); } } catch (InterruptedException e) { System.out.println(firstName + secondName + e); } } private String firstName; private String secondName; private long aWhile; } public class Main { public static void main(String[] args) { Thread first = new TryThread("A ", "a ", 200L); Thread second = new TryThread("B ", "b ", 300L); Thread third = new TryThread("C ", "c ", 500L); first.start(); second.start(); third.start(); try { Thread.sleep(3000); first.interrupt(); second.interrupt(); third.interrupt(); } catch (Exception e) { System.out.println(e); } } }