Web应用程序[VehicleRouting]似乎已经启动了一个名为[drools-worker-4]的线程,但未能阻止它

时间:2017-06-09 02:00:42

标签: java multithreading tomcat servlets optaplanner

我使用optaplanner构建车辆路由Web应用程序。当我尝试将我的Web应用程序部署到tomcat 8服务器,并尝试从我的Web浏览器运行它时,它会在我的tomcat日志文件中生成警告。日志说我的Web应用程序启动了一个线程并且未能阻止它,并且可能会造成内存泄漏。 我编写了一个destroy方法,我的ExecutorService对象将调用shutdown方法来确保它启动的每个线程都被终止。这是我的代码:

public class OptimizerService implements IOptimizerService {
    private ExecutorService executor;

    @Override
    public synchronized Boolean startSolving() throws Throwable {
        executor = Executors.newFixedThreadPool(2);
        ...
    }

    ...
    // other methods 
    ...

    @PreDestroy
    public synchronized void destroy() {
        executor.shutdown();
    }
}

但为什么我仍然在tomcat日志中收到这些警告? 这是tomcat日志:

09-Jun-2017 08:25:56.377 WARNING [http-nio-18081-exec-295] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [VehicleRouting] 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)

任何评论将不胜感激。谢谢和问候。

1 个答案:

答案 0 :(得分:0)

paste -d';' file1 file2 会中断线程,但executor.shutdownNow();却没有。后者只是等到任务完成,如果你有一个2小时的解算器运行,那就好运了......

如果executor.shutdown();检测到其线程被中断,它将终止(与普通Solver几乎相同),然后调用Termination。我假设KieSession.dispose()负责任何产生线程的drools。

至少这个理论是:)