users@servlet-spec.java.net

[servlet-spec users] [jsr340-experts] Re: Re: _at_PreDestroy for AsyncListener

From: Rajiv Mordani <rajiv.mordani_at_oracle.com>
Date: Fri, 2 Nov 2012 15:43:27 -0700

On Oct 26, 2012, at 6:25 AM, Rémy Maucherat <rmaucher_at_redhat.com> wrote:

> On 10/25/2012 10:35 PM, Shing Wai Chan wrote:
>> If one invoke the
>> listener = asyncContext.createListener(MyListener.class);
>> then the method corresponding to @PostConstruct in listener will be invoked.
>> The question is when the method corresponding to @PreDestroy is invoked.
>> I propose to call the method associated to @PreDestroy when the request is recycled.
>> In this case, the user should not / cannot store the listener across the request.
> It looks like we made a mistake here.
>
> I think we should have added a destroyListener method, and I suppose this problem wasn't anticipated because the other create* (from the Servlet context) last until the webapp itself is destroyed. Waiting for the request to complete and track all async listener instances that could have been created and then destroy them when the request finally gets recycled would be possible, but it does not guarantee it's not going to break anything.


Can you explain what you mean by "but it does not guarantee its not going to break anything"? The question is what is the lifecycle of an AsyncListener. The @PreDestroy annotation is what is used to give the managed bean an opportunity to clean up. In this case the question is when should we assume that the listener can be "destroyed". I think it is reasonable to assume that when the request is recycled that the listener's pre destroy method should be invoked.

- Rajiv


>
> Rémy
>