# AtomicMarkableReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#pubctors)\|[Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#inhmethods)  

# AtomicMarkableReference

`
public


class
AtomicMarkableReference
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|----------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.concurrent.atomic.AtomicMarkableReference\<V\> |

<br />

*** ** * ** ***

An`AtomicMarkableReference`maintains an object reference along with a mark bit, that can be updated atomically.

Implementation note: This implementation maintains markable references by creating internal objects representing "boxed" \[reference, boolean\] pairs.

## Summary

|                                                                                                                            ### Public constructors                                                                                                                            ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[AtomicMarkableReference](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#AtomicMarkableReference(V,%20boolean))`(V initialRef, boolean initialMark) ` Creates a new`AtomicMarkableReference`with the given initial values. |

|                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                        ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean` | ` `[attemptMark](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#attemptMark(V,%20boolean))`(V expectedReference, boolean newMark) ` Atomically sets the value of the mark to the given update value if the current reference is`==`to the expected reference.                                                                                                                                          |
| ` boolean` | ` `[compareAndSet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#compareAndSet(V,%20V,%20boolean,%20boolean))`(V expectedReference, V newReference, boolean expectedMark, boolean newMark) ` Atomically sets the value of both the reference and mark to the given update values if the current reference is`==`to the expected reference and the current mark is equal to the expected mark.         |
| ` V`       | ` `[get](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#get(boolean[]))`(boolean[] markHolder) ` Returns the current values of both the reference and the mark.                                                                                                                                                                                                                                        |
| ` V`       | ` `[getReference](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#getReference())`() ` Returns the current value of the reference.                                                                                                                                                                                                                                                                      |
| ` boolean` | ` `[isMarked](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#isMarked())`() ` Returns the current value of the mark.                                                                                                                                                                                                                                                                                   |
| ` void`    | ` `[set](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#set(V,%20boolean))`(V newReference, boolean newMark) ` Unconditionally sets the value of both the reference and mark.                                                                                                                                                                                                                          |
| ` boolean` | ` `[weakCompareAndSet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicMarkableReference#weakCompareAndSet(V,%20V,%20boolean,%20boolean))`(V expectedReference, V newReference, boolean expectedMark, boolean newMark) ` Atomically sets the value of both the reference and mark to the given update values if the current reference is`==`to the expected reference and the current mark is equal to the expected mark. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### AtomicMarkableReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public AtomicMarkableReference (V initialRef, 
                boolean initialMark)
```

Creates a new`AtomicMarkableReference`with the given initial values.

<br />

|                    Parameters                     ||
|---------------|------------------------------------|
| `initialRef`  | `V`: the initial reference <br />  |
| `initialMark` | `boolean`: the initial mark <br /> |

## Public methods

### attemptMark

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean attemptMark (V expectedReference, 
                boolean newMark)
```

Atomically sets the value of the mark to the given update value if the current reference is`==`to the expected reference. Any given invocation of this operation may fail (return`false`) spuriously, but repeated invocation when the current value holds the expected value and no other thread is also attempting to set the value will eventually succeed.

<br />

|                              Parameters                              ||
|---------------------|-------------------------------------------------|
| `expectedReference` | `V`: the expected value of the reference <br /> |
| `newMark`           | `boolean`: the new value for the mark <br />    |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

### compareAndSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean compareAndSet (V expectedReference, 
                V newReference, 
                boolean expectedMark, 
                boolean newMark)
```

Atomically sets the value of both the reference and mark to the given update values if the current reference is`==`to the expected reference and the current mark is equal to the expected mark.

<br />

|                              Parameters                               ||
|---------------------|--------------------------------------------------|
| `expectedReference` | `V`: the expected value of the reference <br />  |
| `newReference`      | `V`: the new value for the reference <br />      |
| `expectedMark`      | `boolean`: the expected value of the mark <br /> |
| `newMark`           | `boolean`: the new value for the mark <br />     |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

### get

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public V get (boolean[] markHolder)
```

Returns the current values of both the reference and the mark. Typical usage is`boolean[1] holder; ref = v.get(holder); `.

<br />

|                                                         Parameters                                                          ||
|--------------|---------------------------------------------------------------------------------------------------------------|
| `markHolder` | `boolean`: an array of size of at least one. On return,`markHolder[0]`will hold the value of the mark. <br /> |

|                    Returns                     ||
|-----|-------------------------------------------|
| `V` | the current value of the reference <br /> |

### getReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public V getReference ()
```

Returns the current value of the reference.

<br />

|                    Returns                     ||
|-----|-------------------------------------------|
| `V` | the current value of the reference <br /> |

### isMarked

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isMarked ()
```

Returns the current value of the mark.

<br />

|                     Returns                     ||
|-----------|--------------------------------------|
| `boolean` | the current value of the mark <br /> |

### set

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void set (V newReference, 
                boolean newMark)
```

Unconditionally sets the value of both the reference and mark.

<br />

|                          Parameters                          ||
|----------------|----------------------------------------------|
| `newReference` | `V`: the new value for the reference <br />  |
| `newMark`      | `boolean`: the new value for the mark <br /> |

### weakCompareAndSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean weakCompareAndSet (V expectedReference, 
                V newReference, 
                boolean expectedMark, 
                boolean newMark)
```

Atomically sets the value of both the reference and mark to the given update values if the current reference is`==`to the expected reference and the current mark is equal to the expected mark. This operation may fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to`compareAndSet`.

<br />

|                              Parameters                               ||
|---------------------|--------------------------------------------------|
| `expectedReference` | `V`: the expected value of the reference <br />  |
| `newReference`      | `V`: the new value for the reference <br />      |
| `expectedMark`      | `boolean`: the expected value of the mark <br /> |
| `newMark`           | `boolean`: the new value for the mark <br />     |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |