class MyThread implements Runnable{ @Override public void run() { for (int i = 0; i < 5; i++){ System.out.println(Thread.currentThread().getName() + ": " +i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } public class Test { public static void main(String[] args) throws InterruptedException { new Thread(new MyThread()).start(); } }