Annotation Interface Lock


@InterceptorBinding @Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited public @interface Lock

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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    Supports inline instantiation of the Lock annotation.
    static enum 
    Designates the type of lock to be READ or WRITE.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    long
    The maximum amount of time to wait to obtain the lock.
    Indicates whether to obtain the lock on the bean instance in exclusive or shared mode.
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Value for accessTimeout() that indicates that the lock that permits running a bean method must be obtained immediately.
    static final long
    Value for accessTimeout() that indicates to wait as long as necessary to obtain the lock that permits running a bean method.
  • Field Details

  • Element Details

    • type

      Lock.Type type

      Indicates whether to obtain the lock on the bean instance in exclusive or shared mode.

      Returns:
      The Lock.Type to use
      Default:
      WRITE
    • accessTimeout

      long accessTimeout

      The 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 CompletionException that chains a TimeoutException is thrown from the method invocation attempt.

      Use the IMMEDIATE constant to avoid waiting.

      Use the UNLIMITED constant 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