Class ContextualInstanceStrategy<T>

  • Type Parameters:
    T -

    public abstract class ContextualInstanceStrategy<T>
    extends Object
    This component allows optimized strategies for obtaining contextual instances of a given bean to be plugged in. By default a contextual instance of a bean is obtained by first obtaining the context for bean's scope and then by calling Context.get(jakarta.enterprise.context.spi.Contextual) or Context.get(jakarta.enterprise.context.spi.Contextual, CreationalContext) on the given context. This algorithm matches the defaultStrategy() implementation. In addition, specialized implementations are provided. For ApplicationScoped beans a special strategy is used which caches application-scoped bean instances in a volatile field. This implementation respects the possibility of an instance being destroyed via AlterableContext and the cached instance is flushed in such case. For SessionScoped, ConversationScoped and RequestScoped beans a special strategy is used which caches contextual bean instances in a ThreadLocal. This implementation respects the possibility of an instance being destroyed via AlterableContext and the cached instance is flushed in such case. This is done indirectly by RequestScopedCache.
    Author:
    Jozef Hartinger