Code example for AtomicInteger

Methods: addAndGet

0
	public int getValue() { 
		return i.get(); 
	} 
 
	private void evenIncrement() { 
		i.addAndGet(2); 
	} 
 
	public void run() { 
		while (true) 
			evenIncrement(); 
	} 
 
	public static void main(String[] args) { 
		new Timer().schedule(new TimerTask() { 
			public void run() { 
				System.err.println("Aborting"); 
				System.exit(0); 
			} 
		}, 5000); // Terminate after 5 seconds 
		ExecutorService exec = Executors.newCachedThreadPool();