Java examples for Thread:Thread
Each thread should print "Hello from Thread <num>!",
structure your program such that the threads print their greetings in reverse order
public class Exercise4 implements Runnable { static int threadCount = 1; public static void main(String[] args) { reverseHello();//from ww w .ja v a 2s . c o m } public static void reverseHello() { if (threadCount <= 10) { Thread thread = new Thread(new Exercise4()); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } } @Override public void run() { threadCount++; reverseHello(); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } System.out .println("Hello from " + Thread.currentThread().getName()); } }