Drools failed to stop worker threads when shutting down web application in Tomcat 8

266 views
Skip to first unread message

Puhong You-c

unread,
Aug 26, 2017, 4:38:28 PM8/26/17
to Drools Usage
We use Drools 7.2.0.Final in our RulesEnhine web application which is deployed to Tomcat 8. When shutting down the web application, the following messages are logged into the Tomcat catalina.log --

26-Aug-2017 15:14:55.602 WARNING [http-nio-8080-exec-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [RulesEngine] appears to have started a thread named [drools-worker-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 java.lang.Thread.run(Thread.java:745)
26-Aug-2017 15:14:55.606 WARNING [http-nio-8080-exec-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [RulesEngine] appears to have started a thread named [drools-worker-2] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 java.lang.Thread.run(Thread.java:745)
26-Aug-2017 15:14:55.610 WARNING [http-nio-8080-exec-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [RulesEngine] appears to have started a thread named [drools-worker-3] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 java.lang.Thread.run(Thread.java:745)
26-Aug-2017 15:14:55.613 WARNING [http-nio-8080-exec-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [RulesEngine] appears to have started a thread named [drools-worker-4] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 java.lang.Thread.run(Thread.java:745)

There was a bug report related to this problem --


This bug was marked as fixed in 7.0.0.Beta1, but the problem still exists in 7.2.0.Final.

=======

Our application obtains a handle to KieBase via the following calls during initialization phase --

   private KieContainer kieContainer = null;

   public KieBase loadCrashRulesKnowledgeBase() {
        try {
        if (kieContainer == null) {
        kieContainer = KieServices.Factory.get().getKieClasspathContainer();
        }
    KieBase kieBase = kieContainer.getKieBase(CRASH_RULES_KBASE_NAME);
        kieBase.addEventListener(new RulesEngineConfigurationEventListener(this));
        return kieBase;
        } catch (Exception e){
            throw new RulesEngineRuntimeException("Could Not Load CrashRulesKnowledgeBase from Drools Package.");
        }
  }

During application shutdown, we try to clean up the KieContainer like this -- 

     if (kieContainer != null) {
     kieContainer.dispose();
    }

Anyone know how to properly stop the drools worker threads during web application shutdown?







Reply all
Reply to author
Forward
0 new messages