4 Replies Latest reply on Apr 15, 2015 12:37 PM by Maxim Maslov

    Memory leak in ManagedScheduledExecutorService?

    Maxim Maslov Newbie



      I suspect that memory leak occurs when background task is scheduled with ManagedScheduledExecutorService.schedule method.


      Here is a code that does the thing:

      public class MySingleton {
          protected ManagedScheduledExecutorService executor;
          private ScheduledFuture<?> future;
          private void postConstruct() {
              future = executor.schedule(() -> {}, new MyTrigger());
          protected class MyTrigger implements Trigger
              public Date getNextRunTime(LastExecution lastExecutionInfo, Date taskScheduledTime)
                  return new Date(new Date().getTime() + 1000);
              public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime)
                  return false;


      When this bean is running on WildFly 8.1 or 8.2, a number of chained ArrayList$Sublist objects in the server heap is increasing by 1 every seconds.

      Do I do anything wrong?


      It looks very similar to WFLY-4187, but I do not put any interceptors on the run() method of a Runnable (as the ticket's author did).

        • 1. Re: Memory leak in ManagedScheduledExecutorService?
          Tomaz Cerar Master

          from where are ArrayList$Sublist? are they still there after few full GC cycles?

          if so, who is holding references?

          • 2. Re: Memory leak in ManagedScheduledExecutorService?
            Maxim Maslov Newbie

            Tomaz Cerar wrote:

            from where are ArrayList$Sublist?

            I suspect that ArrayList$Sublists are produced by the org.jboss.invocation.InterceptionContext.clone() method (jboss-invocation-1.2.1.Final.jar module):

                 * Clone this interceptor context instance.  The cloned context will resume execution at the same point that
                 * this context would have at the moment it was cloned.
                 * @return the copied context
                public InterceptorContext clone() {
                    final InterceptorContext clone = new InterceptorContext();
                    final Map<String, Object> contextData = this.contextData;
                    if (contextData != null) {
                        clone.contextData = new HashMap<String, Object>(contextData);
                    clone.target = target;
                    clone.method = method;
                    clone.constructor = constructor;
                    clone.parameters = parameters;
                    clone.timer = timer;
                    final int next = interceptorIterator.nextIndex();
                    clone.setInterceptors(interceptors.subList(next, interceptors.size()));
                    return clone;


            are they still there after few full GC cycles?

            The Sublists survive full GC.


            if so, who is holding references?

            The last ArrayList$Sublist object in the chain is referenced by org.jboss.invocation.InterceptorContext object ('interceptorIterator' field)


            The object before the last is referenced by:

            - the last ArrayList$Sublist object and

            - org.jboss.invocation.InterceptorContex object ('interceptors' field)


            The first ArrayList$Sublist object refers to ArrayList that contains two objects:

            [0] : org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor

            [1] : org.jboss.invocation.TerminalInterceptor

            • 3. Re: Memory leak in ManagedScheduledExecutorService?
              Eduardo Martins Apprentice

              Yes, it's WFLY-4187, and it's fixed at Jboss Invocation 1.4.1.Final, which should be integrated in next WildFly 9 release.