43 |
|
* <p> Methods {@code awaitAvailability} and {@code getSequence} can |
44 |
|
* be used together to define (partially) optimistic read-only methods |
45 |
|
* that are usually more efficient than ReadWriteLocks when they |
46 |
< |
* apply. These read-only methods typically read multiple field |
47 |
< |
* values into local variables when the lock is not held, retrying if |
48 |
< |
* the sequence number changed while doing so. Alternatively, because |
49 |
< |
* {@code awaitAvailability} accommodates reentrancy, a method can |
50 |
< |
* retry a bounded number of times before switching to locking mode. |
51 |
< |
* While conceptually straightforward, expressing these ideas can be |
52 |
< |
* verbose. For example: |
46 |
> |
* apply. These read-only methods typically read multiple {@code |
47 |
> |
* volatile} field values into local variables when the lock is not |
48 |
> |
* held, retrying if the sequence number changed while doing so. |
49 |
> |
* Alternatively, because {@code awaitAvailability} accommodates |
50 |
> |
* reentrancy, a method can retry a bounded number of times before |
51 |
> |
* switching to locking mode. While conceptually straightforward, |
52 |
> |
* expressing these ideas can be verbose. For example: |
53 |
|
* |
54 |
|
* <pre> {@code |
55 |
|
* class Point { |
56 |
< |
* private double x, y; |
56 |
> |
* private volatile double x, y; |
57 |
|
* private final SequenceLock sl = new SequenceLock(); |
58 |
|
* |
59 |
|
* void move(double deltaX, double deltaY) { // an exclusively locked method |