public class MyTask implements Runnable { private final int MAX_COUNT = 100000; private CountMonitor mon; public MyTask(CountMonitor mon) { this.mon = mon; } @Override public void run() { System.out.println("Starting! Shared counter = " + mon.getCounter()); for (int i = 0; i < MAX_COUNT; i++) { mon.increment(); } System.out.println("Done! Shared counter = " + mon.getCounter()); } }