public class UseCounter4 {
	Counter c;                         
	public UseCounter4() {
		c = new Counter(0);
		for (int i = 0; i < 10; i++) {
            final int userID = i;
		    new Thread() {
		        public void run() { 
                    callCounter(userID); 
                }
		    }.start();
		}
	}

	private void callCounter(int userID) {
        int val = 0;
        try {
            Thread.sleep(20);
		    val = c.getAndIncrement(); 
        } catch (InterruptedException e) {}
		System.out.println("User " + userID + " reporting. Value of counter = " + val);
	}
	
	public static void main(String[] args) {
		new UseCounter4();
	}
}

class Counter {
	private int value;

	public Counter(int c) {
		value = c;
	}

	public int getValue() {
		return value;
	}

	public int getAndIncrement() {
		int temp = 0;
		temp = value;
		value = temp + 1;
		return temp;
	}
}
