繁体   English   中英

Tomcat,Spring,调度程序-内存泄漏

[英]Tomcat, Spring, Schedulers - memory leaks

我有一些类,这些类的方法使用Scheduled批注进行批注。

当我在Tomcat中停止/取消部署/重新部署此应用程序时,我收到以下消息:

"The following web applications were stopped (reloaded, undeployed), but their classes from previous runs are still loaded in memory, thus causing a memory leak (use a profiler to confirm):
/my-app
/my-app
/my-app"

我试图在ContextClosed处理程序中“自动装配” ThreadPoolTask​​Executor,并使用shutdown()方法停止它。 但这没有帮助。 似乎计划的方法(线程)不受Tomcat控制。

我也尝试设置taskExecutor.setWaitForTasksToCompleteOnShutdown(false)。

当我转储堆时,我只能看到包含计划方法和与之关联的类的类(实例)。

这导致我们的服务器()在几天后停止响应请求的问题。

配置:

@Configuration
@EnableWebMvc
@EnableScheduling
public class AppConfig {
    @Bean
    public ThreadPoolTaskScheduler taskScheduler(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.setMaxPoolSize(40);
        executor.setQueueCapacity(400);
        executor.setWaitForTasksToCompleteOnShutdown(false);
        executor.initialize();

        return executor;
    }
}

调度程序:

@Component
public class HistoryCleaner {

    @Autowired
    private HistoryService historyService;
    @Autowired
    private AppProperties app;

    @Scheduled(fixedDelay = 10000)
    public void cleanHistory() {
        ...
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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