Code example for AtomicReference

Methods: compareAndSetset

	// subclass's readObject method to initialize our state. 
	protected AbstractFoo() { 
	protected final void initialize(int x, int y) {
		if (!init.compareAndSet(State.NEW, State.INITIALIZING))
			throw new IllegalStateException("Already initialized");
		this.x = x;
		this.y = y;
		// Do anything else the original constructor did 
	// These methods provide access to internal state so it can 
	// be manually serialized by subclass's writeObject method. 
	protected final int getX() { 
		return x;