10 Replies Latest reply on Oct 2, 2012 1:40 AM by L.F. Huw

    EJB3 TimerService memory leak ?

    poueck Newbie

      Hi all,

       

      I have build an application that uses a lot of EJB timer, and performance descrease damatically when JVM tenured gen memory becomes full.

      That's why I suspect a memory link.

       

      Running TIJmp to profile the JVM memory, I see that all timer related object are not garbage collected and growing.

       

      The question is: Is it a bug in the EJB3 TimerService or do I badly use the service.

       

      Here is a code example:

       

      @Stateless
      @LocalBean
      public class MyProcessorBean {
      
           private static final RoundRobinQueue<QueueEntry> QUEUE = new RoundRobinQueue<QueueEntry>(new QueueEntryHasher());
      
           private @Resource TimerService timerService;
      
           public void submit(QueueEntry queueEntry) {
                synchronized(QUEUE) {
                     QUEUE.add(queueEntry);
                     if (QUEUE.size()==1)
                          this.timerService.createSingleActionTimer(0, new TimerConfig(null,false));
                }
           }
      
           @Timeout
           public void queueProcessing(Timer timer) {
                synchronized(QUEUE) {
                     // Get the next queue entry
                     QueueEntry queueEntry = QUEUE.poll();
      
                     // If queue is not empty, schedule next processing immediatly
                     if (!QUEUE.isEmpty())
                          this.timerService.createSingleActionTimer(0,new TimerConfig(null,false));
      
                     if (queueEntry != null) {
                          // Do the job for this entry ...
                     } else {
                          // Timer with empty queue ...
                     }
                }
           }
      }
      

       

      I uses this mecanism for the following reasons:

      - The queue is not processed in FIFO (round robin queue on some specific entry fields (QueueEntryHasher)

      - I want to have a transaction par element process

      - I want a multitheading process

       

      After adding a lot of element in the queue, the tenured gen memory becomes full, application becomes extremly slow.

      This is the case on JBoss 6.1 and JBoss 7.0.2

       

      TIJmp show me the following under JBoss 6.1:

      HeapWalk1.JPG

      After adding elements in MyProcessorBean:

       

      HeapWalk2.JPG

       

      Any hint that can help ?

       

      Thanks in advance.

       

      Regards,

       

      Poueck.