1 2 Previous Next 23 Replies Latest reply on May 27, 2013 8:04 AM by veitg

    EJB lookup during server shutdown




      I´m needing call a EJB on AS7 server shutdown, but when I try, I get the exception "No EJB client context is available" .


      The resumed code :


      public class FirstSessionBean {
          private AnySession anySession;
          public void testMethod() throws Exception {
           //wait a little to execute server shutdown  (CTRL + C on the console)
              // if i try to shutdown the server, here i get "No EJB client context is available" ;
              System.out.println("PARTE 2 ");




      The full Stack (of the real code):




      16:09:42,350 ERROR [stderr] java.lang.IllegalStateException: No EJB client context is available

      16:09:42,353 ERROR [stderr]     at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:235)

      16:09:42,355 ERROR [stderr]     at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)

      16:09:42,358 ERROR [stderr]     at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

      16:09:42,360 ERROR [stderr]     at $Proxy59.carregaCce(Unknown Source)

      16:09:42,363 ERROR [stderr]     at com.ed.ejb.timers.nfe.TesteAssync.a(TesteAssync.java:32)

      16:09:42,364 ERROR [stderr]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      16:09:42,366 ERROR [stderr]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      16:09:42,368 ERROR [stderr]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      16:09:42,369 ERROR [stderr]     at java.lang.reflect.Method.invoke(Method.java:597)

      16:09:42,371 ERROR [stderr]     at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)

      16:09:42,372 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,374 ERROR [stderr]     at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

      16:09:42,375 ERROR [stderr]     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)

      16:09:42,377 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,378 ERROR [stderr]     at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

      16:09:42,379 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,381 ERROR [stderr]     at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

      16:09:42,382 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,383 ERROR [stderr]     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

      16:09:42,385 ERROR [stderr]     at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

      16:09:42,386 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,389 ERROR [stderr]     at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

      16:09:42,391 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,392 ERROR [stderr]     at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)

      16:09:42,394 ERROR [stderr]     at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)

      16:09:42,395 ERROR [stderr]     at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)

      16:09:42,396 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,397 ERROR [stderr]     at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

      16:09:42,399 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,400 ERROR [stderr]     at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

      16:09:42,402 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,403 ERROR [stderr]     at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

      16:09:42,405 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,406 ERROR [stderr]     at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:43)

      16:09:42,408 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,409 ERROR [stderr]     at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

      16:09:42,411 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,412 ERROR [stderr]     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

      16:09:42,413 ERROR [stderr]     at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)

      16:09:42,415 ERROR [stderr]     at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173)

      16:09:42,416 ERROR [stderr]     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      16:09:42,418 ERROR [stderr]     at org.jboss.as.ejb3.component.interceptors.AsyncVoidInterceptorFactory$Task.run(AsyncVoidInterceptorFactory.java:75)

      16:09:42,419 ERROR [stderr]     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

      16:09:42,420 ERROR [stderr]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

      16:09:42,422 ERROR [stderr]     at java.lang.Thread.run(Thread.java:662)

      16:09:42,423 ERROR [stderr]     at org.jboss.threads.JBossThread.run(JBossThread.java:122)




      Manual lookup and lookup on the @PreDestroy method doesnt work either.


      Any Ideias? How can I do something like this?




        • 1. Re: EJB lookup during server shutdown

          I forgot to say that I'm using JBoss As 7.1.1 


          • 2. Re: EJB lookup during server shutdown

            Can you try with AS7 upstream? I think I fixed this yesterday.

            • 3. Re: EJB lookup during server shutdown

              Tried with the latest jboss-as-7.1.2.Final-SNAPSHOT (https://ci.jboss.org/jenkins/job/JBoss-AS-7.x-latest/) and the problem remains the same.



              Maybe I forgot to add something? My tests were made using a timerservice as first EJB, then I call the "FirstSessionBean".

              • 4. Re: EJB lookup during server shutdown

                I actually added another fix in this area today, and a test: https://github.com/jbossas/jboss-as/commit/d8b5feda4adcf488440a0b8a864344c80816f4c3


                It does not look like these made it into the build that you would have downloaded.

                • 5. Re: EJB lookup during server shutdown

                  I think i need to wait the next nightly build right?



                  Thanks Stuart



                  Just to complement:  Using manual lookup the problem is "javax.naming.NameNotFoundException".

                  • 6. Re: EJB lookup during server shutdown

                    The problem still exists on the latest build ( 777 )



                    More information:


                    Using the previous example:


                    11:09:38,278 ERROR [stderr] java.lang.IllegalStateException: No EJB client context is available

                    11:09:38,279 ERROR [stderr]     at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:235)

                    11:09:38,280 ERROR [stderr]     at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)

                    11:09:38,280 ERROR [stderr]     at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)



                    Using manual lookup:


                    11:03:38,660 ERROR [stderr] java.lang.IllegalArgumentException: JBAS011857: NamingStore is null

                    11:03:38,662 ERROR [stderr]     at org.jboss.as.naming.NamingContext.<init>(NamingContext.java:149)

                    11:03:38,665 ERROR [stderr]     at org.jboss.as.naming.NamingContext.<init>(NamingContext.java:122)

                    11:03:38,668 ERROR [stderr]     at org.jboss.as.naming.InitialContext.<init>(InitialContext.java:85)

                    11:03:38,670 ERROR [stderr]     at org.jboss.as.naming.InitialContextFactory.getInitialContext(InitialContextFactory.java:44)



                    Using @EJB inside a TimerService:


                    11:08:09,973 ERROR [stderr] java.lang.IllegalStateException

                    11:08:09,974 ERROR [stderr]     at org.jboss.msc.value.InjectedValue.getValue(InjectedValue.java:47)

                    11:08:09,975 ERROR [stderr]     at org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.getTimedObjectId(TimedObjectInvokerImpl.java:106)

                    11:08:09,976 ERROR [stderr]     at org.jboss.as.ejb3.timerservice.TimerImpl.toString(TimerImpl.java:615)

                    11:08:09,977 ERROR [stderr]     at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2794)

                    11:08:09,977 ERROR [stderr]     at java.util.Formatter$FormatSpecifier.print(Formatter.java:2677)

                    11:08:09,979 ERROR [stderr]     at java.util.Formatter.format(Formatter.java:2433)

                    11:08:09,979 ERROR [stderr]     at java.util.Formatter.format(Formatter.java:2367)

                    11:08:09,980 ERROR [stderr]     at java.lang.String.format(String.java:2769)

                    11:08:09,980 ERROR [stderr]     at org.jboss.logmanager.ExtLogRecord.formatRecord(ExtLogRecord.java:379)

                    11:08:09,981 ERROR [stderr]     at org.jboss.logmanager.ExtLogRecord.getFormattedMessage(ExtLogRecord.java:344)

                    11:08:09,982 ERROR [stderr]     at org.jboss.logmanager.formatters.Formatters$10.renderRaw(Formatters.java:357)

                    11:08:09,982 ERROR [stderr]     at org.jboss.logmanager.formatters.Formatters$JustifyingFormatStep.render(Formatters.java:148)

                    11:08:09,983 ERROR [stderr]     at org.jboss.logmanager.formatters.MultistepFormatter.format(MultistepFormatter.java:86)

                    11:08:09,983 ERROR [stderr]     at org.jboss.logmanager.ExtFormatter.format(ExtFormatter.java:35)

                    11:08:09,984 ERROR [stderr]     at org.jboss.logmanager.handlers.WriterHandler.doPublish(WriterHandler.java:49)

                    11:08:09,984 ERROR [stderr]     at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:64)

                    11:08:09,985 ERROR [stderr]     at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:283)



                    Can I open an Jira ?

                    • 7. Re: EJB lookup during server shutdown

                      I would say this falls under https://issues.jboss.org/browse/AS7-484.

                      1 of 1 people found this helpful
                      • 8. Re: EJB lookup during server shutdown



                        Really looks like the problem. I will ask on the jira. This problem are making the project i'm working impossible to end using AS 7. Maybe I will need to fallback to AS6.



                        • 9. Re: EJB lookup during server shutdown

                          Im running out of options. I tried to fallback to as6 and then  i started to have problems with persistent timer service (Just like https://community.jboss.org/thread/162938 ) .


                          Maybe there is a way to put my application as the first resource to shutdown and make the other services wait a little while I execute some operations (services like weld, ejb3) ?


                          I tried to create my "ServerShutdownMBean", but there is no support any more ( StartupServiceMBean  was removed)


                          Any more options?

                          • 10. Re: EJB lookup during server shutdown

                            This is really a problem with the way EJB specs are written. The lifecycle is intentionally very loose to allow things like circular references. The problem is that if you allow circularity you can't have strict ordering. Singleton has a solution for this using @DependsOn. We are looking at opening this up for other bean types, but it would of course be a proprietary feature.

                            1 of 1 people found this helpful
                            • 11. Re: EJB lookup during server shutdown

                              In AS 7.1.1 you can use @DependsOn for singleton beans, to make sure that other EJB's don't shut down until the the singleton has shut down. Even though the spec says that you can only use this to reference other singleton beans, we have expanded this so you can reference any type of bean. 


                              In AS7 upstream I have added a feature where you can use use @DependsOn on any session bean (not just singletons), AS7 upstream also has some other fixes to make sure that the EJB Client context does not shut down until all EJB's have shut down.

                              • 12. Re: EJB lookup during server shutdown

                                I will give a try on the latest build tomorrow and post the results.


                                Thanks to you both !

                                • 13. Re: EJB lookup during server shutdown

                                  The problem still happen.  Can you confirm ? Maybe I coded something wrong?


                                  Just hit ctrl + c when the "STOP SERVER NOW!!!!" message shows and the exception will happen.


                                  Here is my test: (I cleaned up the @DependsOn beacause I tried a lot of combinations and the problem persist, where I put this annotation?)





                                  public class InitializerBean {
                                            private FirstSessionBean firstSessionBean;
                                            public void init() {
                                                      try {
                                                      } catch (Exception e) {



                                  public class FirstSessionBean {
                                            private SecondSessionBean secondSession;
                                            public void someOperation() {
                                                      try {
                                                                // while (true) {
                                                                System.out.println("STOP SERVER NOW!!!!");
                                                                System.out.println("INVOCATION COMPLETED");
                                                                // }
                                                      } catch (Exception e) {
                                                                System.out.println("INVOCATION FAILED! ");
                                            public void destroy() {



                                  public class SecondSessionBean {
                                            public void someOperation() {
                                                      System.out.println("Some operation");
                                            public void destroy() {



                                  If you guys prefer, I have uploaded the eclipse project and the ejb.jar file:





                                  • 14. Re: EJB lookup during server shutdown

                                    Just to complement: Tried with the latest 7.1.2 SNAPSHOT

                                    1 2 Previous Next