|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Documented
@Target(value={METHOD,CONSTRUCTOR})
public @interface RequiresLockDeclares that the method or constructor to which this annotation applies assumes that the caller holds the named locks. Analysis of the method/constructor proceeds as if the named locks were held; call sites of the method are scrutinized to determine if the precondition is satisfied.
The list of locks is allowed to be empty, in which case it means that the method/constructor does not require any locks to be held by the caller.
StateLock, that indicates that synchronizing
on the field stateLock (which must be declared to be final)
protects the two long fields use to represent the position of the
object. The RequiresLock annotation is used specify that StateLock must be held when invoking the setX or setY
methods.
@Region("private AircraftState")
@RegionLock("StateLock is stateLock protects AircraftState")
public class Aircraft {
private final Object stateLock = new Object();
@InRegion("AircraftState")
private long x, y;
public void setPosition(long x, long y) {
synchronized(stateLock)
setX(x);
setY(y);
}
}
@RequiresLock("StateLock")
private void setX(long value) {
x = value;
}
@RequiresLock("StateLock")
private void setY(long value) {
y = value;
}
}
@annotate tag.
/**
* @annotate Region("private AircraftState")
* @annotate RegionLock("StateLock is stateLock protects AircraftState")
*/
public class Aircraft {
private final Object stateLock = new Object();
/**
* @annotate InRegion("AircraftState")
*/
private long x, y;
public void setPosition(long x, long y) {
synchronized(stateLock)
setX(x);
setY(y);
}
}
/**
* @annotate RequiresLock("StateLock")
*/
private void setX(long value) {
x = value;
}
/**
* @annotate RequiresLock("StateLock")
*/
private void setY(long value) {
y = value;
}
}
RegionLock| Required Element Summary | |
|---|---|
String |
value
A comma-separated list of zero or more lock names. |
| Element Detail |
|---|
public abstract String value
value = lockSpecification *("," lockSpecification)
lockSpecification = qualifiedLockSpecification / simpleLockSpecification
simpleLockSpecification = simpleLockName ["." ("readLock" / "writeLock")]
qualifiedLockSpecification = qualifiedLockName ["." ("readLock" / "writeLock")]
simpleLockName = IDENTIFIER ; Lock from the receiver (same as "this:IDENTIFIER")
qualifiedLockName = parameterLockName / typeQualifiedLockName / innerClassLockName
parameterLockName = simpleExpression ":" IDENTIFIER ; Lock from a method/constructor parameter
simpleExpression = "this" / IDENTIFER ; Receiver or parameter name
typeQualifiedLockName = typeExpression ":" IDENTIFIER ; Static lock qualified by a class name
typeExpression = IDENTIFIER *("." IDENTIFIER)
innerClassLockName = namedType "." "this" ":" IDENTIFIER ; Lock from an enclosing instance
namedType = IDENTIFIER *("." IDENTIFIER)
IDENTIFIER = Legal Java Identifier
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||