12 Replies Latest reply on May 27, 2013 1:10 AM by Rangasamy A

    Exception with EJB Scheduler in JBoss7.1.1.Final

    Chandra Dontula Newbie

      I am getting the following error with my EJB scheduler deployed. I have the below EJB deployed as part of my ear file

       

      package com.nielsen.emm.crediting.base.ejb;

       

       

      import javax.ejb.Schedule;

      import javax.ejb.Singleton;

      import javax.ejb.Timeout;

      import javax.ejb.Timer;

       

       

      import org.apache.log4j.Logger;

       

       

      import com.nielsen.emm.crediting.base.manager.CreditingBusinessManager;

       

       

      @Singleton

      public class DimentionDataManagementEJB {

       

       

                private static final Logger logger = Logger

                                    .getLogger(DimentionDataManagementEJB.class);

       

       

                CreditingBusinessManager bm = new CreditingBusinessManager();

       

       

                @Timeout

                public void timeout() {

                }

       

       

                @Schedule(dayOfWeek = "*", hour = "*", minute = "*/2", second = "*", year = "*", persistent = false)

                public void refreshDiAppDataCache(Timer timer) {

       

       

                          try {

                                    bm.refreshDiAppDataCache();

                          } catch (Exception ex) {

                                    ex.printStackTrace();

                                    logger.error("Exception refreshing the Application Dimention data cache:"

                                                        + ex.getMessage());

                          }

                }

      }

       

      The application is executing the operation and showing output when printed on console, but still throwing the following exception. Also observed that it is not running in the specified interval of times. Can someone please help me to resolve this.

      13:04:06,040 ERROR [org.jboss.as.ejb3] (EJB default - 2) JBAS014120: Error invoking timeout for timer: [id=8a913c04-fe64-4bc0-89b1-3c7ac8863be8 timedObjectId=CreditingApp-1.0.CreditingEjb-1.0.DimentionDataManagementEJB auto-timer?:true persistent?:false timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@1acd8cf initialExpiration=Wed Sep 05 00:00:00 IST 2012 intervalDuration(in milli sec)=0 nextExpiration=Wed Sep 05 13:04:07 IST 2012 timerState=IN_TIMEOUT: javax.ejb.ConcurrentAccessTimeoutException: JBAS014373: EJB 3.1 PFD2 4.8.5.5.1 concurrent access timeout on org.jboss.invocation.InterceptorContext$Invocation@1f32ade - could not obtain lock within 5000MILLISECONDS

                at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:100) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

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

        • 1. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
          Nicklas Karlsson Master

          Does the refresh-job take a long time to complete? If so you can use @AccessTimeout to make it a bit more patient (look at the section of the spec the exception indicates)

          • 2. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
            Chandra Dontula Newbie

            Hi Karlsson,

             

                 The refresh method does not take much time, the functionality of this is to get the 5 rows from database using hibernate and storing it into infinispan cache. Hardly it is taking 3secs.

             

            I have tried as you have suggested, by adding the @AccessTimeout (value=-1) at class level and at method level, in both the cases I am facing the same issue.

             

            After this I am getting ConcurrentAccessException

             

            As this error occurs only in case od singleton and stateful ejb, I have modified the @Singleton to @Stateless, after this it is not throwing any exception but the problem is

            The method is getting called continuously even the interval given is 2minutes.

             

            Please let me know if you have any idea.

             

            Thanks,

            Chandu.

            • 3. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
              Nicklas Karlsson Master

              You see it called too often?

               

              Tried

               

              @Schedule(minute = "*/2", hour = "*", persistent = false)

               

              ?

              • 4. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                Chandra Dontula Newbie

                Hi Karlsson,

                 

                     Thanks for your support, I was supposed to reply before but wanted to test completely befor replying.

                 

                     I was tested in similar lines(not exactly yours) by giving @Schedule(minute = "*/2", persistent = false),  but when I deploy the application the scheduler is not getting called at all. But might be yours work and need to test.

                 

                     What I have observed is, when we include lower dimentions in schedule annotations than what we require, JBoss is taking the least dimentions

                     Ex: @Schedule(dayOfWeek = "*", hour = "*", minute = "*/2", second = "*", year = "*", persistent = false)

                          it is taking second = "*" instead of minute = "*/2" and invoking the method every second and causing the above problems.

                 

                     so I have modified the Schedule annotation to @Schedule(year = "*", dayOfWeek = "*", hour = "*", minute = "*/2", persistent = false)

                    

                Now I observed no issues get raised and event my Singleton class working fine at the scheduled intervals of time i.e 2minutes in my case.

                 

                This could be useful for anyone who is facing similar issues with EJB schedulers.

                 

                Thanks,

                Chandu.


                • 5. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                  Nicklas Karlsson Master

                  Yes, the scheduling semantics is a bit tricky in that respect, I had similar issues with my timer in my own case.

                  • 6. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                    jaikiran pai Master

                    Chandra Dontula wrote:

                     

                     

                         What I have observed is, when we include lower dimentions in schedule annotations than what we require, JBoss is taking the least dimentions

                         Ex: @Schedule(dayOfWeek = "*", hour = "*", minute = "*/2", second = "*", year = "*", persistent = false)

                              it is taking second = "*" instead of minute = "*/2" and invoking the method every second and causing the above problems.

                     

                         so I have modified the Schedule annotation to @Schedule(year = "*", dayOfWeek = "*", hour = "*", minute = "*/2", persistent = false)

                        

                    The spec states that the default value for hour minute and second is 0 unless specified. So unless you specify hour = * (i.e. any hour) then it will only fire at midnight.

                    • 7. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                      shadowcreeper Apprentice

                      The way I read the docs, using 'minute="*/2", second="*"' means it will not run in odd numbered minutes (possibly unless there is overflow from the previous even numbered minute) but it will run 1x per second of every even numbered minute (if execution takes longer than 1 second, this might run over into the next odd numbered minute). While 'minute="*/2"' means run it 1x every even numbered minute at second '0' (the default).

                      • 8. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                        Rangasamy A Newbie

                        Hi Chanda,

                         

                        I have the same issue. In my case the @sheduler should run every 5sec ie:@Schedule( second = "*/5",  minute = "*",hour = "*",year = "*", persistent = false).My class is singleton and stateless ejb bean.

                         

                        When i start the server, the timer is runing every seconds. So i am getting concurrentaccess issue. 

                         

                        Any idea?

                        • 9. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                          Wolf-Dieter Fink Master

                          You need only to specify sec/min/hr (this values default to "0") all other values are "*" by default.

                           

                          If you set second = "*/5" it should be every 5 sec, this works for me.

                          What if you set only minute/hour to "*" it should be started every minute?

                          Maybe you have another timer firing. How your class look like?

                          • 10. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                            Rangasamy A Newbie

                            Hi Fink,

                            Thanks for you reply.

                             

                            The issue is not comming for minimal records(10 rec). But when i was testing with more than 50 records the exception is coming

                             

                            15:17:45,021 ERROR [org.jboss.as.ejb3] (EJB default - 8) JBAS014120: Error invoking timeout for timer: [id=2e245a44-2dd8-4752-8b45-d86c9ea49627 timedObjectId=fts.fts.JobServiceImpl auto-timer?:true persistent?:false timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@114c02f initialExpiration=Fri May 24 00:00:00 IST 2013 intervalDuration(in milli sec)=0 nextExpiration=Fri May 24 15:17:50 IST 2013 timerState=RETRY_TIMEOUT: javax.ejb.ConcurrentAccessTimeoutException: JBAS014373: EJB 3.1 PFD2 4.8.5.5.1 concurrent access timeout on org.jboss.invocation.InterceptorContext$Invocation@c67b0e - could not obtain lock within 5000MILLISECONDS.

                             

                            I have cross checked the data in db, everything seems fine. But in log ,i have found the above exception. is it possible to prevent this exception ?

                             

                            for your reference my class:

                             

                            @Singleton

                            public class JobServiceImpl implements JobService {

                             

                                @Schedule(hour = "*", minute = "*", second = "*/5", persistent = false, info = "Every Five second")

                                @Override

                                public void archiveJob() {

                             

                                    String jbossNodeName = System.getProperty(FtsConstants.JBOSS_NODE_NAME);

                                    logger.debug("Jboss node name : " + jbossNodeName);

                                    // To prevent duplicate publish in cluster env:Hardcodeing the one node

                                    // name in property file

                                    if (jbossNodeName.equalsIgnoreCase(ConfigurationSettingsFactory.getConfigValue("jboss-node-name"))) {

                                        run();

                                    }

                             

                                }

                            }

                            • 11. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                              Wolf-Dieter Fink Master

                              Could it be that the method is still running?

                              In case of a Singleton the next invocation will wait until the singleton is not blocked with another invocation. The timeout for that is 5sec by default (as stated in the log message).

                              So if you run the timer each 5sec and it run more than 5sec you will see that error.

                              • 12. Re: Exception with EJB Scheduler in JBoss7.1.1.Final
                                Rangasamy A Newbie

                                Thanks Fink.

                                now i have created seprate thread to execute the job process. Every thing is working fine now.