com.beans.properties.atomic.AtomicProperty Maven / Gradle / Ivy
package com.beans.properties.atomic;
import com.beans.properties.PropertyBase;
/**
*
* A thread-safe implementation of {@link com.beans.Property Property}, holding a
* variable which is accessed for writing or reading through {@link #set(Object)}
* and {@link #get()}.
*
*
* This implementation relays on the fact that the Java Language Specifications guarantee that an access (read/write)
* to a volatile field is atomic, and will be visible to all threads.
*
*
* @param type of the property data.
*
* @since JavaBeans 1.0
*/
public class AtomicProperty extends PropertyBase {
private volatile T mValue;
public AtomicProperty(T initialValue) {
mValue = initialValue;
}
/**
* Initializes the property with a value of null.
*/
public AtomicProperty() {
this(null);
}
@Override
public void set(T value) {
mValue = value;
}
@Override
public T get() {
return mValue;
}
}