A lock that governs concurrent access to a CDI managed bean.
When the Lock annotation is applied to a bean class or method,
a single lock controls access to an instance of the bean. The lock is obtained,
either in exclusive or shared
mode, by invoking bean methods. If the bean implementation internally accesses
one of its own methods or fields, that access is not subject to the lock.
A bean method that does not have a Lock annotation inherits
the Lock annotation, if present, of the class that declares the method.
A bean class that has a method annotated Lock, but does not have a
Lock annotation of its own at the class level, operates according to
the default values of the Lock annotation when bean methods that are
not annotated Lock are invoked.
- Since:
- 3.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSupports inline instantiation of theLockannotation.static enumDesignates the type of lock to be READ or WRITE. -
Optional Element Summary
Optional Elements -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longValue foraccessTimeout()that indicates that the lock that permits running a bean method must be obtained immediately.static final longValue foraccessTimeout()that indicates to wait as long as necessary to obtain the lock that permits running a bean method.
-
Field Details
-
IMMEDIATE
static final long IMMEDIATEValue foraccessTimeout()that indicates that the lock that permits running a bean method must be obtained immediately. Otherwise, aCompletionExceptionthat chains aTimeoutExceptionis thrown.- See Also:
-
UNLIMITED
static final long UNLIMITEDValue foraccessTimeout()that indicates to wait as long as necessary to obtain the lock that permits running a bean method.- See Also:
-
-
Element Details
-
type
Lock.Type type- Returns:
- The Lock.Type to use
- Default:
WRITE
-
accessTimeout
long accessTimeoutThe maximum amount of time to wait to obtain the lock. If the lock that allows running the method cannot be obtained within the specified amount of time, a
CompletionExceptionthat chains aTimeoutExceptionis thrown from the method invocation attempt.Use the
IMMEDIATEconstant to avoid waiting.Use the
UNLIMITEDconstant to avoid timing out.The supplied timeout value must be positive or one of the constants described above.
- Returns:
- the time to wait to obtain a lock
- Default:
60L
-
unit
TimeUnit unit- Returns:
- units used for the specified accessTimeout value.
- Default:
SECONDS
-