[cdi-dev] [JBoss JIRA] (CDI-228) Clarify that _all_ @Dependent beans created for a containers method invocation will get destroyed after the method exits

Mark Struberg (JIRA) jira-events at lists.jboss.org
Mon Sep 3 02:54:32 EDT 2012


    [ https://issues.jboss.org/browse/CDI-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12715328#comment-12715328 ] 

Mark Struberg commented on CDI-228:
-----------------------------------

A quick summary of what we discussed last week:

We have 4 different kind of method injections:

1. Observer methods
2. Producer methods
3. @Inject constructor
4. @Inject methods

The CDI-1.0 spec already defines that @Dependent scoped beans injected into an Observer method (case 1.) must get destroyed after the method invocation.

For the other 3 cases there is no such a definition, which indicates that those @Dependent scoped contextual instances need to remain stored in the CreationalContext of the respective bean.

The CDI-1.0 spec further was overly strict and did forbid injecting a non-serializable @Dependent bean into a method parameter of a passivation capable bean. We removed this restriction already in CDI-1.1.

Action: We will introduce a new annotation @Transient (or similar) which denotes that the parameter shall not get stored in the CreationalContext of it's owner but instead shall get thrown away immediately after the method invocation. 

The spec wording will get changed to amend the section 6.4.2

OLD:
"• all @Dependent scoped contextual instances injected into method parameters of a disposer method or observer method of any other event are destroyed when the invocation completes," 

NEW:
"• all @Dependent scoped contextual instances injected into method parameters which are marked or assumed as @Transient are destroyed when the invocation completes,"

In addition to that we change the definition of observer methods 10.4.1:

OLD:
"In addition to the event parameter, observer methods may declare additional parameters, which may declare qualifiers. These additional parameters are injection points."

NEW:
"In addition to the event parameter, observer methods may declare additional parameters, which may declare qualifiers. These additional parameters are injection points where @Transient is assumed for.

                
> Clarify that _all_ @Dependent beans created for a containers method invocation will get destroyed after the method exits
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CDI-228
>                 URL: https://issues.jboss.org/browse/CDI-228
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Contexts
>    Affects Versions: 1.1.EDR
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>             Fix For: 1.1 (Proposed)
>
>
> This clarification is intended for all methods which gets invoked by the CDI container and create a new @Dependent contextual instance especially for this invocation. This can happen in @Observes, @Produces, @Disposal and @Inject methods as well as in @Inject contructors. Basically any @Dependent method-parameter InjectionPoint.
> Despite it's atm not specified whether this @Dependent instance will get stored, most containers store it in the CreationalContext of the bean containing the invoked method. This behaviour can lead to mem leaks and non-serializibility issues.
> TASK: Define that any @Dependent contextual instance will get properly destroyed after such method invocations. 
> There are 2 things we need to think about:
> 1.) any @PreDestroy method of those beans will get invoked after the method invocation, even if the @Dependent instance will stored away in a member field and still being used later. This will not make any problems in most cases. We just need to make people aware that this will happen.
> 2.) As any Decorator or Interceptor is also an @Dependent instance on our 'temporary' created @Dependent method parameter, those Interceptors and Decorators will _not_ be available after the method invocation. Storing away this bean and re-using it later will probably cause an Exception.
> I still think this is a small problem compared to creating tons of mem leaks. There are quite a few workarounds possible: 
> *) Instead of @Inject methods you can use @Inject field + @PostConstruct to initialize it.
> *) We might add an additional annotation which denotes either @Transactional or au contraire: @Keep for the method-param InjectionPoint

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the cdi-dev mailing list