jsr340-experts@servlet-spec.java.net

[jsr340-experts] Re: _at_PreDestroy for AsyncListener

From: Rémy Maucherat <rmaucher_at_redhat.com>
Date: Fri, 26 Oct 2012 15:25:26 +0200

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.

Rémy