3 Replies Latest reply on Jul 27, 2017 5:16 PM by Ralph Soika

    Stateful Session Bean - @PreDestroy never called?

    Ralph Soika Apprentice

      I 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;
      public class ArchiveServiceStateful implements SessionSynchronization {
        public String doArchive(String file,byte[] content)  {
        return null;
        public void afterBegin() throws EJBException, RemoteException {
        System.out.println("after begin....");
        public void afterCompletion(boolean arg0) throws EJBException, RemoteException {
        System.out.println("after completion... status="+arg0);
        public void beforeCompletion() throws EJBException, RemoteException {
        System.out.println("before complete...");
        public void onPostConstruct() {
        public void onPreDestroy() {
        public void onPostActivate() {
        public void onPrePassivate() {


      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?