This is a JSF 2 application running on WAS8.0. Here is the code to support one page bean.
@Named("mySessionBean") @SessionScoped @Stateful @LocalBean @StatefulTimeout(unit = TimeUnit.MINUTES, value = 10) public class MySessionBean implements Serializable { @PostConstruct public void init() { System.out.println("start MySessionBean: " + this.hashCode()); } @PreDestroy public void cleanup() { System.out.println("destroy MySessionBean: " + this.hashCode()); } .... }
The session timeout value set in the web.xml file is less than the bean timeout. When I launch the application, I see a printout from @PostConstruct, but I never see it from @PreDestroy. I tried the following 2 scripts: 1. logout - invalidateSession; 2. Just wait until the session ends.
I am not an application developer. The designer insists on making the bean support a session with a bean state. I think a more general approach would be to simply make them a CDI bean. But anyway, when I change the annotation only to CDI, I also start getting a printout from @PreDestroy
@Named("mySessionBean") @SessionScoped public class MySessionBean implements Serializable { .....
My question is, why am I not getting the @PreDestroy method call in the first case? If I donโt see how the @PreDestroy call is called, are there other ways I can track the beans โsupportโ life cycle (in this case, a session with a bean state). Thanks!
chaoshangfei
source share