| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Integer one = …;
AtomicStampedReference ai = new AtomicStampedReference(one, 0);
Based on 34 examples
public class AtomicStampedReference extends Object
An {@code AtomicStampedReference} maintains an object reference along with an integer "stamp", that can be updated atomically.
Implementation note. This implementation maintains stamped references by creating internal objects representing "boxed" [reference, integer] pairs.
Constructor Summary | |
---|---|
AtomicStampedReference(Object initialRef, int initialStamp) Creates a new with the given initial values. |
Method Summary | |
---|---|
boolean |
attemptStamp(Object expectedReference, int newStamp) Atomically sets the value of the stamp to the given update value if the current reference is to the expected reference. |
boolean |
compareAndSet(Object expectedReference, Object newReference, int expectedStamp, int newStamp) Atomically sets the value of both the reference and stamp to the given update values if the current reference is to the expected reference and the current stamp is equal to the expected stamp. |
Object |
get(int[] stampHolder) Returns the current values of both the reference and the stamp. |
Object |
Returns the current value of the reference. |
int |
getStamp() Returns the current value of the stamp. |
void |
Unconditionally sets the value of both the reference and stamp. |
boolean |
weakCompareAndSet(Object expectedReference, Object newReference, int expectedStamp, int newStamp) Atomically sets the value of both the reference and stamp to the given update values if the current reference is to the expected reference and the current stamp is equal to the expected stamp. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AtomicStampedReference(Object initialRef, int initialStamp)
initialRef
- the initial referenceinitialStamp
- the initial stampMethod Detail |
---|
public boolean attemptStamp(Object expectedReference, int newStamp)
expectedReference
- the expected value of the referencenewStamp
- the new value for the stamppublic boolean compareAndSet(Object expectedReference, Object newReference, int expectedStamp, int newStamp)
expectedReference
- the expected value of the referencenewReference
- the new value for the referenceexpectedStamp
- the expected value of the stampnewStamp
- the new value for the stamppublic Object get(int[] stampHolder)
stampHolder
- an array of size of at least one. On return,
{@code stampholder[0]} will hold the value of the stamp.public Object getReference()
public int getStamp()
public void set(Object newReference, int newStamp)
newReference
- the new value for the referencenewStamp
- the new value for the stamppublic boolean weakCompareAndSet(Object expectedReference, Object newReference, int expectedStamp, int newStamp)
May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to {@code compareAndSet}.
expectedReference
- the expected value of the referencenewReference
- the new value for the referenceexpectedStamp
- the expected value of the stampnewStamp
- the new value for the stamp
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |