Spring Boot 线程没有停止 - 内存泄漏?

问题描述

如果已经有人回答了,我很抱歉,我似乎找不到它。我确实看到了 this。我们使用的是 springboot 2.3.1.RELEASE、jdk 1.8、tomcat-dbcp 8.5.11。我们正在尝试检索大量记录并将其保存到数据库中,为此我们正在使用 CompletableFuture

在应用程序完成运行后终止应用程序后,我会看到此堆栈跟踪:

The web application [ROOT] appears to have started a thread named [pool-35-thread-12] 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:2044)
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

代码

 for(String department : departmentList) 
 {
    Executor executor = Executors.newFixedThreadPool(20);
    // Some logic to get deptKeyLists which is List<List<Long>>
    for(List<Long> deptKeyList: deptKeyLists)
     {
         // A REST call to get item information within the department
             for(ItemContainerDTO itemContainerDTO : data.getBody().getItemContainer())
                 {
                     for(ItemDTO itemDTO : itemContainerDTO.getItems())
                     {
                         futureList.add(CompletableFuture.supplyAsync(() ->
                         service.saveDataToDB(requestId,itemContainerDTO,itemDTO),executor)
                                 .exceptionally(exception -> {
                                        log.error("Exception occurred for requestId - {}",requestId);
                                        
                                        return null;
                                 }));
                     }
                 }
                 futureList.stream()
                 .filter(f1 -> !f1.isCompletedExceptionally())
                 .map(CompletableFuture::join).forEach(f -> log.info("RequestId : {},Total {}",requestId,f));
    }
 }. 

关于为什么会发生这种情况的任何建议/建议?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)