简体   繁体   中英

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?

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();
    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM