0 Replies Latest reply on Jul 26, 2011 1:06 AM by Nitin Jain

    EJB3 Timer not removed from "TIMERS" table on AS shutdown

    Nitin Jain Newbie

      Hello Forum,

       

      I have a EJB3 Timer bean deployed in JBoss5.1.0 server. The AS has been configured to persist the timer in the database. On AS startup, timer is persisted in "TIMERS" table (Oracle database) and is invoked at the set intervals.

       

      public class SessionCleanupServlet implements ServletContextListener {
          private SessionCleanupTimerImpl _cleanupTimerImpl = null;
      
          @Override
          public void contextDestroyed(ServletContextEvent event) {
               _systemLog.info("Session cleanup timer removal started.....................");
               _cleanupTimerImpl.end();
          }
          @Override
          public void contextInitialized(ServletContextEvent event) {
              _cleanupTimerImpl = new SessionCleanupTimerImpl();
              _cleanupTimerImpl.start();
          }
      }
      
      

       

      public class SessionCleanupTimerImpl {
          public void start() {
              try {
                  SessionCleanupTimer sessionManagement = getObjectFactoryInstanceByPropertyKey().getSessionCleanupTimer();
                  sessionManagement.initializeTimer(10000, getSessionCleanupTimeOutPeriodInMillSeconds(), "SessionCleanup");
              } catch(Exception exception) {
                  systemLog.error("Error occurred during session cleanup : ", exception);
              }
          }
          public void end() {
              try {
                  SessionCleanupTimer sessionManagement = getObjectFactoryInstanceByPropertyKey().getSessionCleanupTimer();
                  sessionManagement.cancelTimer("SessionCleanup");
              } catch(Exception exception) {
                  systemLog.error("Error occurred during session cleanup : ", exception);
              }
          }
      }
      

       

      @Stateless
      @Remote(SessionCleanupTimer.class)
      public class SessionCleanupTimerBean implements SessionCleanupTimer {  
          @Resource
          private TimerService _timerService;
          @EJB
          private ManageBankflexSession _manageBankflexSession;
          public void initializeTimer(long startDate, long timeout, String timerName) {
              .....
       .....
          }
          @Timeout
          public void sessionCleanup(Timer timer) {
              ......
       ......
          }
          public void cancelTimer(String timerName) {
              for (Timer myTimer : retrieveAllTimers()) {
                  if ((timerName.equals(myTimer.getInfo()))) {
                      myTimer.cancel();
                  }
              }
          }
          public Collection<Timer> retrieveAllTimers() {
              return _timerService.getTimers();
          }
      }
      

      Now when I shutdown the AS (ctrl+c), I was expecting that the record from the "TIMERS" table will be removed; however it is not happening and the following exception is thrown.

       

      2011-07-26 10:02:36,945 INFO  (JBoss Shutdown Hook) Session cleanup timer removal started.....................
      2011-07-26 10:02:36,959 ERROR (JBoss Shutdown Hook) Error occurred during session cleanup : 
      javax.ejb.EJBException: java.lang.NullPointerException
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.aspects.remoting.ReplicantsManagerInterceptor.invoke(ReplicantsManagerInterceptor.java:52)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:85)
       at org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor.invoke(ClusteredIsLocalInterceptor.java:52)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
       at $Proxy1026.invoke(Unknown Source)
       at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
       at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
       at $Proxy1028.cancelTimer(Unknown Source)
       at com.app.impl.sessionmanagement.SessionCleanupTimerImpl.end(SessionCleanupTimerImpl.java:63)
       at com.app.impl.servlets.SessionCleanupServlet.contextDestroyed(SessionCleanupServlet.java:54)
       at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3949)
       at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4615)
       at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:1175)
       at org.apache.catalina.core.StandardContext.destroy(StandardContext.java:4705)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
       at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
       at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performUndeployInternal(TomcatDeployment.java:596)
       at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performUndeploy(TomcatDeployment.java:570)
       at org.jboss.web.deployers.AbstractWarDeployment.stop(AbstractWarDeployment.java:480)
       at org.jboss.web.deployers.WebModule.stopModule(WebModule.java:133)
       at org.jboss.web.deployers.WebModule.stop(WebModule.java:102)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
       at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
       at $Proxy38.stop(Unknown Source)
       at org.jboss.system.microcontainer.StartStopLifecycleAction.uninstallAction(StartStopLifecycleAction.java:56)
       at org.jboss.system.microcontainer.StartStopLifecycleAction.uninstallAction(StartStopLifecycleAction.java:37)
       at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleUninstallAction(SimpleControllerContextAction.java:79)
       at org.jboss.dependency.plugins.action.AccessControllerContextAction.uninstall(AccessControllerContextAction.java:131)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.uninstall(AbstractControllerContextActions.java:58)
       at org.jboss.dependency.plugins.AbstractControllerContext.uninstall(AbstractControllerContext.java:354)
       at org.jboss.dependency.plugins.AbstractController.uninstall(AbstractController.java:1664)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1275)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1179)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1234)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:827)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
       at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
       at org.jboss.system.ServiceController.stop(ServiceController.java:510)
       at org.jboss.system.microcontainer.jmx.ServiceControllerStartStopLifecycleCallback.uninstall(ServiceControllerStartStopLifecycleCallback.java:52)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.beans.info.plugins.AbstractBeanInfo.invoke(AbstractBeanInfo.java:300)
       at org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext.invoke(AbstractKernelControllerContext.java:286)
       at org.jboss.dependency.plugins.AbstractLifecycleCallbackItem.uninstall(AbstractLifecycleCallbackItem.java:112)
       at org.jboss.dependency.plugins.AbstractController.handleLifecycleCallbacks(AbstractController.java:1570)
       at org.jboss.dependency.plugins.AbstractController.handleUninstallLifecycleCallbacks(AbstractController.java:1546)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1273)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1179)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1234)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1179)
       at org.jboss.dependency.plugins.AbstractController.uninstall(AbstractController.java:655)
       at org.jboss.dependency.plugins.AbstractController.uninstall(AbstractController.java:568)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.undeploy(BeanMetaDataDeployer.java:153)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.undeploy(BeanMetaDataDeployer.java:51)
       at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalUndeploy(AbstractSimpleRealDeployer.java:69)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.undeploy(AbstractRealDeployer.java:112)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.undeploy(DeployerWrapper.java:196)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doUndeploy(DeployersImpl.java:1469)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doUninstallParentLast(DeployersImpl.java:1376)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doUninstallParentLast(DeployersImpl.java:1369)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.uninstall(DeployersImpl.java:1331)
       at org.jboss.dependency.plugins.AbstractControllerContext.uninstall(AbstractControllerContext.java:354)
       at org.jboss.dependency.plugins.AbstractController.uninstall(AbstractController.java:1664)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1275)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:827)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:694)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679)
       at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
       at org.jboss.system.server.profileservice.repository.ProfileDeployAction.uninstall(ProfileDeployAction.java:95)
       at org.jboss.system.server.profileservice.repository.AbstractProfileAction.uninstall(AbstractProfileAction.java:70)
       at org.jboss.system.server.profileservice.repository.AbstractProfileService.uninstall(AbstractProfileService.java:375)
       at org.jboss.dependency.plugins.AbstractControllerContext.uninstall(AbstractControllerContext.java:354)
       at org.jboss.dependency.plugins.AbstractController.uninstall(AbstractController.java:1664)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1275)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1179)
       at org.jboss.dependency.plugins.AbstractController.uninstallContext(AbstractController.java:1234)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:827)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
       at org.jboss.system.server.profileservice.repository.AbstractProfileService.deactivateProfile(AbstractProfileService.java:402)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.deactivateProfiles(ProfileServiceBootstrap.java:388)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.shutdown(ProfileServiceBootstrap.java:345)
       at org.jboss.bootstrap.AbstractServerImpl.shutdownServer(AbstractServerImpl.java:571)
       at org.jboss.bootstrap.AbstractServerImpl$ShutdownHook.run(AbstractServerImpl.java:909)
      Caused by: java.lang.NullPointerException
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       ... 121 more
      

       

      The AS started in "all" configuration using "run.bat -c all -g AppCluster -u 239.255.100.10".

       

      Please advise.

       

      Regards,

      Nitin