Search code examples
javamultithreadingconcurrencydrools

Drools using ThreadPoolExecutor in Java EE 7 application causes problems on redeploy


We are using Drools 6.3.0Final in a JavaEE 7 application on Weblogic 12.2.1. When our application is initially deployed we see 8 Threads named "drools-worker-X" where X ranges from 1 to 8 (on a 4-core CPU with HT). Now when we redeploy the application the 8 threads remain in state "Park" and 8 new Threads are created (again numbered from 1 to 8). This continues on every redeployment.

As we found out the class ExecutorProviderImpl in package org.drools.core.concurrent creates a new ThreadPoolExecutor with a corePoolSize and maxPoolSize both set to the number of CPU cores and the Timeout to 60s. Once we redeployed a certain number of times the JVM gets slow and our application is no longer running properly.

Is there any way to properly shut down those worker threads when our application shuts down?


Solution

  • You could implement a Startup-EJB that shuts down the ExecutorService in a @PreDestroy-annotated method. I just tested it in our own project, and it seems to work like a charm.

    import java.util.concurrent.ExecutorService;
    import org.kie.internal.concurrent.ExecutorProviderFactory;
    ...
    
    @Startup
    @Singleton
    public class PlausiServiceLifecycleManager {
    
        /**
         * Shuts down Drools' internal ExecutorService, so that its threads can terminate.
         */
        @PreDestroy
        public void shutdown() {
            ExecutorService executor = (ExecutorService) ExecutorProviderFactory.getExecutorProvider().getExecutor();
            executor.shutdown();
        }
    
    
    }