Hi, MyFaces is already using all available Listeners (HttpSessionAttributeListener, HttpSessionListener, ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener) to invoke @PreDestroy on the Managed Beans and this happens via a pass-through from StartupServletContextListener, so you don't have to configure two listeners in web.xml (or tld).
The problem is, as you thought, that those listeners (e.g. HttpSessionListener) are not invoked on a container shutdown/restart. Only contextDestroyed from ServletContextListener is invoked (tested today on Apache Tomcat 6). I will not change anything of the existing behavior, I just want to make sure that all still existing ManagedBeans get their @PreDestroy method called in contextDestroyed. But I would not get a reference to them, if I do not register them in a ManagedBeanRegistry. Regards, Jakob 2010/1/13 Jan-Kees van Andel <[email protected]> > Hey, > > How about an HttpSessionListener? I'm not sure if > HttpSessionListener.contextDestroyed is invoked on shutdownthough. > Probably not... > > I'm afraid the only option is custom bookkeeping, maybe using an > HttpSessionListener/ServletContextListener to publish events to the > Registry. > I see some issues with this approach: > 1 Configuration becomes more difficult for the application developer, > because these two Listeners become required configuration. > 2 Managing objects yourself may be tricky business. An option could be > to use WeakReference/WeakHashMap for this so you don't accidentally > keep your objects alive. > 3 What to do with regards to session replication on a clustered > environment? I'm not sure this will become an issue, but it wouldn't > surprise me if it will. > > Regards, > Jan-Kees > > > 2010/1/13 Jakob Korherr <[email protected]>: > > Hi guys, > > > > To ensure the execution of the ManagedBean's @PreDestroy methods on a > > container shutdown/restart, I would like to introduce a > ManagedBeanRegistry, > > in which all active ManagedBeans from all scopes are referenced. > > > > The problem is the following: At the moment on a container shutdown or > > restart, only contextDestroyed is invoked (tested in tomcat 6), thus only > > the @PreDestroy methods of all ApplicationScoped ManagedBeans will be > > invoked, but not those of any existing ManagedBeans in session, request, > > view (and maybe also custom) scope, because they can not be referenced in > > contextDestroyed(). > > > > Any opinions on that? > > > > Thanks in advance! > > > > Regards, > > Jakob > > >
