Stateful Session Bean - @PreDestroy never called?
rsoika Jul 27, 2017 3:40 PMI made a strange observation concerning statful session beans running in Wildfly 10.
This is my bean example:
import java.rmi.RemoteException; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.EJBException; import javax.ejb.LocalBean; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; import javax.ejb.SessionSynchronization; import javax.ejb.Stateful; @Stateful @LocalBean public class ArchiveServiceStateful implements SessionSynchronization { public String doArchive(String file,byte[] content) { System.out.println("doArchive..."); return null; } @Override public void afterBegin() throws EJBException, RemoteException { System.out.println("after begin...."); } @Override public void afterCompletion(boolean arg0) throws EJBException, RemoteException { System.out.println("after completion... status="+arg0); } @Override public void beforeCompletion() throws EJBException, RemoteException { System.out.println("before complete..."); } @PostConstruct public void onPostConstruct() { System.out.println("@PostConstruct..."); } @PreDestroy public void onPreDestroy() { System.out.println("@PreDestroy..."); } @PostActivate public void onPostActivate() { System.out.println("@PostActivate..."); } @PrePassivate public void onPrePassivate() { System.out.println("@PrePassivate..."); } }
I call the 'doArchive' method from a statles session bean and got the following log messages:
imixs-archive-office_1 | 19:26:43,728 INFO [stdout] (default task-48) @PostConstruct... imixs-archive-office_1 | 19:26:43,745 INFO [stdout] (default task-48) @PostConstruct... imixs-archive-office_1 | 19:26:43,751 INFO [stdout] (default task-48) @PostConstruct... imixs-archive-office_1 | 19:26:43,758 INFO [stdout] (default task-48) @PostConstruct... imixs-archive-office_1 | 19:26:43,766 INFO [stdout] (default task-48) @PostConstruct... imixs-archive-office_1 | 19:26:43,946 INFO [stdout] (default task-48) after begin.... imixs-archive-office_1 | 19:26:43,946 INFO [stdout] (default task-48) doArchive... imixs-archive-office_1 | 19:26:43,952 INFO [stdout] (default task-48) before complete... imixs-archive-office_1 | 19:26:43,981 INFO [stdout] (default task-48) after completion... status=true
So the method onPostConstruct() is called 5 times and all other call back methods are not called.
It looks like each call of my bean method creates 5 new instances of the stateful session bean but never a PreDestroy ore a PrePassivate.
Should I worry about that?
===
Ralph