2 Replies Latest reply on May 25, 2011 5:51 AM by Gabriele Contini

    EJB3 Timers: OutOfMemory error when handling large number of

    Alexander Bollaert Newbie

      Hi,

      I have an MDB that needs to start a timer in some cases when it receives a message. This is implemented in terms of an EJB3 timeout method. However, it seems that JBoss is creating a thread per timer. This is causing OutOfMemory errors because the VM cannot allocate new threads for the timers, eventually resulting in a crash of the server when handling large loads (20000 timers). It is necessary to create the timers, so changing the code to not use timers is not an option.

      I've googled around a bit for a a solution to this problem, and came across https://jira.jboss.org/jira/browse/EJBTHREE-1330. This issue does mention a workaround (using StrictMaxPool instead of the standard evergrowing ThreadlocalPool. But my MDBs are already using the StrictMaxPool (15 instances strictMaximum), and this does not seem to help.

      I would assume that there is a way to configure the TimerService itself to use a thread pool, but the Jira issue does not specify how this could be done, nor does the documentation.

      I would really appreciate it someone could shed some light on this... If there is no way of limiting the threads created by the TimerService, I'll have to change the implementation. But if there is some way of changing this, I would like to know how to do this because it would be the most elegant solution...

      Thanks in advance,

      Alexander