Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-6874

TimerImpl should set ACTIVE state before scheduling to avoid race condition

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • JBossAS-5.1.0.GA
    • JBossAS-4.0.5.GA, JBossAS-4.2.0.GA, JBossAS-4.2.1.GA, JBossAS-4.2.2.GA, JBossAS-4.2.3.GA, JBossAS-5.0.0.GA, JBossAS-5.0.1.GA, JBossAS-5.1.0.Beta1, JBossAS-5.1.0.CR1
    • Scheduling/Timers
    • None
    • Low

      TimerImpl sets ACTIVE state after it's scheduled the timer task which means that you can have a race
      condition leading to something like this:

      2009-04-28 18:55:03,370 45084 DEBUG [org.jboss.ejb.txtimer.TimerImpl] (ScannerThread setTimerState: created
      2009-04-28 18:55:03,372 45086 DEBUG [org.jboss.ejb.txtimer.TimerImpl] (EJB-Timer-2[target=jboss.j2ee:service=EJB3,jar=acme-ejb3.jar,name=ProblematicTimerManagerProxyBean] run: [id=2,target=[target=jboss.j2ee:service=EJB3,jar=acme-ejb3.jar,name=ProblematicTimerManagerProxyBean],remaining=-438372,periode=0,created]
      2009-04-28 18:55:03,372 45086 DEBUG [org.jboss.ejb.txtimer.TimerImpl] (EJB-Timer-2[target=jboss.j2ee:service=EJB3,jar=acme-ejb3.jar,name=ProblematicTimerManagerProxyBean] setTimerState: in_timeout
      2009-04-28 18:55:03,372 45086 DEBUG [org.jboss.ejb.txtimer.TimerImpl] (ScannerThread setTimerState: active

      Sometimes, the timer can kick off even before it's timer state has been set to active, which means that active state will be set after in_timeout.
      What's the effect of this? After the timer has executed, this means that the finally clause in TimerTaskImpl.run() won't be executed and hence,
      the timer won't be deleted from the database. This leads to multiple timer executions.

      Please find attached a thread dump where you can see EJB-Timer-1 being executed correctly, including removal from database, but EJB-Timer-2 is not.

              rh-ee-galder Galder Zamarreño
              rh-ee-galder Galder Zamarreño
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: