As stated in bkail, the semantics of @Stateless beans have vendor specificity. In EJB 3.1, we added the @AccessTimeout annotation, which can be used in the bean class or the @Stateless , @Stateful or @Singleton bean @Singleton .
@AccessTimeout
In a general sense, this annotation portable indicates to what extent the caller will wait if a wait condition occurs while accessing simultaneously. For each bean type, waiting conditions will occur when:
@Singleton - The @Lock(WRITE) method is used, and the concurrency container is used. By default, all @Lock(WRITE) methods @Lock(WRITE) .@Stateful - any instance method is called and a second call is made. OR @Stateful bean is in a transaction, and the caller calls it from outside this transaction.@Stateless - There are no instances in the pool. However, as already noted, the union of semantics, if any, is not covered by the specification. If the semantics of the provider association are related to the wait condition, then @AccessTimeout should be applied.
Using
@AccessTimeout is just a convenient wrapper around the long and TimeUnit tuples commonly used in the java.util.concurrent API.
import java.util.concurrent.TimeUnit; @Target({METHOD, TYPE}) @Retention(RUNTIME) public @interface AccessTimeout { long value(); TimeUnit unit() default TimeUnit.MILLISECONDS; }
If a class or bean method is explicitly specified, it has three possible values:
@AccessTimeout(-1) - Never go into standby mode, wait as long as you need. Potentially forever.@AccessTimeout(0) - Never wait. Throw a ConcurrentAccessException immediately if a wait condition occurs.@AccessTimout(30, TimeUnit.SECONDS) - Wait up to 30 seconds if a wait condition occurs. After that throw ConcurrentAccessTimeoutExcpetion
No default default
Note that the value attribute does not have a default value. This was intentional and intended to inform you that if @AccessTimeout is not explicitly used, the behavior you get depends on the provider.
Some sellers will wait for a pre-configured time and throw javax.ejb.ConcurrentAccessException , some sellers will immediately throw it. When we defined this annotation, it became clear that all of us, sellers, did something different, and forced default could cause problems for existing applications.
Similarly, prior to EJB 3.0 there was no default transaction attribute, and it was different for each provider. Thank goodness EJB 3.0 was quite different, and we could finally say: "For EJB 3.0, beans are REQUIRED by default."