Jboss version: 4.05
DB: SQL Server 2005
OS: Windows Server 2003
We've been having a problem with EJB2.1 timers. Specifically single-shot (run once) timers.
First, our application creates single shot timers, and at the end of the ejbTimeout method for those timers, they create a new single shot timer with a start time in the future. We do this so that the timers execute with a fixed interval between invocations, regardless of how long they take to actually execute.
This appears to work just fine, except that eventually (depending on the interval we choose), the whole timer service will stop. Investigation using SQL server shows two transactions that are locking each other out of the TIMERS table that jboss uses to persist the timers in its DatabasePersistencePolicy. The deadlock seems to occur when one timer is deleting the now used single shot timer, and another is creating the next single shot timer. (DELETE, INSERT).
Since this is a DB deadlock, I assume that it is SQL Server specific. I examined the jboss code where this occurs, but I couldn't fix it with simple synchronization, since that would synchronize all ejbTimeout calls.
Has anyone seen this behavior before? Is there a better way to use the timer service to achieve what we need?
Also, we've seen the same locking when one timer creates another timer to run a task asynchronously.
Right now, our only options seem to be to turn off timer persistence, (NoopPersistencePolicy), or to write our own timer service using mbeans and threads (horrible).