class MyTask implements Runnable { final int MAXCOUNT = 10000; int sharedCounter = 0; public void run() { System.out.println("starting thread, shared counter: " + sharedCounter); for(int i = 0; i < MAXCOUNT; i++){ sharedCounter += 1; } System.out.println("done!, shared counter: " + sharedCounter); } public static void main(String[] args) { Runnable task = new MyTask(); Thread thread1 = new Thread(task); Thread thread2 = new Thread(task); thread1.start(); thread2.start(); // Will make a call to task.run() System.out.println("Expected result: 20000"); } }