9 Replies Latest reply on Apr 2, 2014 9:48 AM by Stephen Coy

    access to other ejb in preDestroy of Singleton causes Component is stopped

    Guenther Bodlak Newbie

      Hi,

       

      I'm using jboss 7.0.2.

      When I try to access a stateless ejb in preDestroy method of Singleton ejb the following exception is thrown:

       

       

      08:37:23,840 ERROR [org.jboss.as.ejb3.tx.CMTTxInterceptor] (MSC service thread 1-1) javax.ejb.EJBTransactionRolledbackException: Component is stopped

      08:37:24,496 WARN  [org.jboss.as.ee.component.BasicComponentInstance] (MSC service thread 1-1) Failed to destroy component instance org.jboss.as.ejb3.component.singleton.SingletonComponentInstance@133f483: javax.ejb.EJBTransactionRolledbackException: Component is stopped

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:133)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:196)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:286)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:182)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

          at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor.processInvocation(SessionInvocationContextInterceptor.java:71)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

          at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:146) [jboss-as-ee-7.0.2.Final.jar:7.0.2.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

          at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:76) [jboss-as-ee-7.0.2.Final.jar:7.0.2.Final]

          at sandbox.singleton.MySessionBean$$$view16.doSomething(Unknown Source)

          at sandbox.singleton.MySingleton.ejbRemove(MySingleton.java:25)

       

      The Singleton:

       

      {code}

      package sandbox.singleton;

      import javax.annotation.PostConstruct;

      import javax.annotation.PreDestroy;

      import javax.ejb.EJB;

      import javax.ejb.Singleton;

      import javax.ejb.Startup;

       

      @Singleton

      @Startup

      public class MySingleton {

       

          @EJB

          MySessionBean mySessionBean;

         

          @PostConstruct

          public void ejbCreate() {

              System.out.println("MySingleton ejbCreate");

          }

         

          @PreDestroy

          public void ejbRemove() {

              System.out.println("MySingleton ejbRemove start");

              mySessionBean.doSomething();

              System.out.println("MySingleton ejbRemove end");

          }

      }

      {code}

       

      The other stateless ejb I want to call:

       

      {code}

      package sandbox.singleton;

      import javax.ejb.Stateless;

       

      @Stateless

      public class MySessionBean {

       

          public void doSomething() {

              System.out.println("MySessionBean doSomething()");

          }

      }

      {code}

       

      Is this a bug or normal EJB 3.1 behaviour?

      How can I call an other ejb in preDestroy?

       

      Many thanks

      Günther

        • 1. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
          Stephen Coy Master

          As I normally do, I turned to the EJB spec to find out what is supposed to happen.

           

          Stateless beans are not permitted to access their enterprise beans from @PostConstruct or @PreDestroy.

           

          On the other hand, both Stateful and Singleton beans are.

           

          Therefore, this sounds like a bug in 7.0.2. Are you able to try on 7.1CR1b and see if it does the same thing?

          • 2. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
            Guenther Bodlak Newbie

            Hi Stephen,

             

            in 7.1CR1b it's the same problem.

             

             

            {code}

            15:38:50,699 ERROR [org.jboss.as.ejb3.tx.CMTTxInterceptor] (MSC service thread 1-4) javax.ejb.EJBTransactionRolledbackException: JBAS011049: Component is stopped

            15:38:50,699 ERROR [org.jboss.ejb3.invocation] (MSC service thread 1-4) JBAS014134: EJB Invocation failed on component MySessionBean for method public void sandbox.singleton.MySessionBean.doSomething(): javax.ejb.EJBTransactionRolledbackException: JBAS011049: Component is stopped

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:139) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:204) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:306) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:57) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

                at sandbox.singleton.MySessionBean$$$view2.doSomething(Unknown Source) [classes:]

                at sandbox.singleton.MySingleton.ejbRemove(MySingleton.java:23) [classes:]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_02]

            {code}

             

            Günther

            • 3. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
              Michael Brill Newbie

              Hi all,

               

              I have quiet a similar setup on JBoss 7.1.0.Final, but same problem here. I'm accessing a stateless bean from the postConstruct of a singleton bean. The strange part is, I do multiple calls on that stateless. The first call works as expected. On the second call I get the following exception:

               

              {code}

              Caused by: java.lang.IllegalStateException: JBAS011049: Component is stopped

                        at org.jboss.as.ee.component.BasicComponent.waitForComponentStart(BasicComponent.java:104) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:127) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:65) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:62) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ejb3.pool.AbstractPool.create(AbstractPool.java:60) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ejb3.pool.strictmax.StrictMaxPool.get(StrictMaxPool.java:128) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:47) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]

                        ... 66 more

              {code}

              • 4. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
                jaikiran pai Master

                Michael Brill wrote:

                 

                Hi all,

                 

                I have quiet a similar setup on JBoss 7.1.0.Final, but same problem here. I'm accessing a stateless bean from the postConstruct of a singleton bean. The strange part is, I do multiple calls on that stateless.

                You are seeing that error in @PostConstruct? What does your code look like?

                • 5. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
                  Michael Brill Newbie

                  Hi and thanks for the response.

                   

                  Well my code is quiet the same as the opening post

                   

                  {code}

                   

                  @Singleton

                  @Startup

                  public class Singleton {

                   

                  @Inject

                  private PropertiesDAO properties;

                   

                  private String value1;

                  private String value2;

                   

                  @PostConstruct

                  public void setUp() {

                   

                       value1 = properies.read(property1);

                       value2 = properties.read(property2);

                       ...

                   

                  }

                   

                  }

                   

                  {code}

                   

                  and

                   

                  {code}

                  @Stateless

                  public class PropertiesDAO {

                   

                       @persistencecontext

                       EntityManager em;

                   

                       ...

                   

                  }

                   

                  {code}

                   

                  I started JBoss in debug mode and set a breakpoint at the first properties call. The DAO is initialised. The strange part is that the first and even second call sometimes succeeds and the value variables are set. Sometimes the Exception comes up on the first call.

                   

                  This is blocking me extremely right now, but I don't want to exclude the possibility of me doing something wrong ;-)

                   

                  Regards,

                   

                  Michael

                  • 6. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
                    Vasko Gjurovski Newbie

                    Did you gyus managed to find some kind of sollution for this?

                    • 8. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
                      Carolina Contiu Newbie

                      Are there are news / possible workarounds for this issue? I'm using AS 7.1.1.

                      • 9. Re: access to other ejb in preDestroy of Singleton causes Component is stopped
                        Stephen Coy Master

                        Try a newer version, such as WildFly 8.0.

                         

                        Alternatively you can checkout and build any of the newer 7.x versions as well.