Hi!

A deep look at how it works:

1st: NormalScoped beans get their OWN CreationalContext. @Dependent scoped will 
get stored into their ‚parent‘ CreationalContext.

2nd: Producer Methods and Producer Fields are OWN Bean<T>. So for your sample 2 
you have 2 different Bean<T>. a.) the @ApplicationScoped FactoryExcample1, b.) 
the @RequestScoped produceBean method (ProducerMethodBean<AnInterface>).

I can only tell you what I >think< will happen in OWB atm :)
For a static producermethod we do _not_ create the ’containing’ instance as we 
do not need it. The Instance<> will get destroyed immediately after the method 
invocation. The created @RequesScoped AnInterface will get stored in the given 
CreationalContext. As this is @RequestScoepd it will be stored in the 
RequestContext and properly be destroyed at the end of the request.

The problem with having to store the CreationalContext for later destruction is 
ONLY immanent to @Dependent scoped beans. 

LieGrue,
strub


> Am 10.03.2015 um 01:16 schrieb Lars-Fredrik Smedberg <[email protected]>:
> 
> Hi
> 
> Some detailed design question and specification question that is based on an 
> earlier discussion in the TomEE group.
> 
> Assume the following:
> 
> - A interface called AnInterface with 3 beans implementing it BeanA, BeanB 
> and BeanC
> - The beans are each annotated by a different @Qualifier, lets call them 
> @QualifierA, @QualifierB and @QualifierC
> 
> Considering the following scenarios/pseudocode does not create a memory leak 
> (as far as I can see using visualvm) I have the following questions:
> 
> a) What of the scenarios are the preferred to use from a performance 
> perspective (OWB wise)?
> b) In scenario 2 and 3 what lifecycle will the @Dependent beans be tied to?
> 
> I try to understand b) above and its relation to the §6.4.1 Dependent Objects 
> of CDI 1.0 specification and specifically the sentence: "An instance of a 
> bean with scope @Dependent obtained by direct invocation of an Instance is a 
> dependent object of the instance of Instance."
> 
> 
> 1)
> 
> @RequestScoped
> public class FactoryExample1 {
> 
>   @Inject @Instance<AnInterface> beans;
>   
>   @Produces @RequestScoped
>   AnInterface produceBean() {
> 
>     return beans.select(<qualifier that selects one of the implementations>);
>   } 
> }
> 
> 2) 
> 
> @ApplicationScoped
> public class FactoryExample1 {
> 
>   @Produces @RequestScoped
>   AnInterface produceBean(@Any Instance<AnInterface> beans) {
> 
>     return beans.select(<qualifier that selects one of the implementations>);
>   } 
> }
> 
> 3) Same as 2) but with a class with a static producer method
> 
> 4) Let BeanA, BeanB and BeanC also be @RequestScoped beans
> 
> @ApplicationScoped
> public class FactoryExample1 {
> 
>   @Inject @Any @Instance<AnInterface> beans;
>   
>   @Produces @RequestScoped
>   AnInterface produceBean() {
> 
>     return beans.select(<qualifier that selects one of the implementations>);
>   } 
> }
> 
> -- 
> Med vänlig hälsning / Best regards
> 
> Lars-Fredrik Smedberg
> 
> STATEMENT OF CONFIDENTIALITY:
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> address(es) and may contain confidential or privileged information. If
> you are not the intended recipient, please notify Lars-Fredrik Smedberg
> immediately at [email protected], and destroy all copies of this 
> message and any attachments.

Reply via email to