Counter
class Counter extends Thread { static int threadCount = 0; int threadNum; public Counter() { threadNum = threadCount++; } public void run() { // Count from 1 to 10 for (int i = 0; i <= 10; i++) { System.out.println("Thread " + threadNum + " : " + i); try { sleep((long)(Math.random() * 100.0)); } catch (InterruptedException e) { } } } }
threadCount
threadNum
CounterApp.txt