class IncrementCounterTask implements Runnable { final SharedCounter sharedCounter; IncrementCounterTask(SharedCounter sharedCounter) { this.sharedCounter = sharedCounter; } @Override public void run() { for (int i = 0; i < 5; i++) { sharedCounter.incrementCounter(); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("The counting thread was interrupted. Exits."); System.exit(1); } } } }