package com.fenixinfotech.thread.playpen;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

public class MonitorTask implements Runnable
{
    private static final Logger logger = LoggerFactory.getLogger(MonitorTask.class);
    private ExecutorService executorService = null;
    private String threadIdentifier;
    private static final long maxDurationMillis = 500L;

    public MonitorTask(ExecutorService executorService, String threadIdentifier)
    {
        this.executorService = executorService;
        this.threadIdentifier = threadIdentifier;
    }

    public void run()
    {
        long started = new Date().getTime();
        while (new Date().getTime() < (started + maxDurationMillis))
        {
            if (executorService instanceof ThreadPoolExecutor)
            {
                ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService;
                logger.info("thread pool {} pool size {} core pool size {} active count {} queue size {} largest pool size {} completed task count {} task count {}",
                        this.threadIdentifier,
                        threadPoolExecutor.getPoolSize(),
                        threadPoolExecutor.getCorePoolSize(),
                        threadPoolExecutor.getActiveCount(),
                        threadPoolExecutor.getQueue().size(),
                        threadPoolExecutor.getLargestPoolSize(),
                        threadPoolExecutor.getCompletedTaskCount(),
                        threadPoolExecutor.getTaskCount());
            }
            else
            {
                logger.warn("unable to get monitoring info from executorService since it is not an instance of ThreadPoolExecutor");
            }
        }
    }
}

@@ -1837,32 +1837,286 @@
 );%0A            %7D
+%0A%0A            // Go to sleep so don't generate too much log, Travis CI has a 4Mb limit%0A            try %7B%0A                Thread.sleep(maxDurationMillis/10);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D
 %0A        %7D%0A    %7D

Put sleep in MonitorTask so it doesn't generate too much log output