gpt4 book ai didi

Spring + Quartz = 内存泄漏

转载 作者:行者123 更新时间:2023-12-04 15:44:12 30 4
gpt4 key购买 nike

我使用以下库。

  • quartz -2.2.1
  • spring-webmvc-3.2.9.RELEASE

  • 在 Apache Tomcat/7.0.52 (Ubuntu) 上。

    我使用 Spring 来配置 Quartz。
    @Configuration
    class QuartzConfig {
    @Bean
    FactoryBean<Scheduler> scheduler() {
    final SchedulerFactoryBean factory = new SchedulerFactoryBeanWithShutdownDelay();
    final Map<String, Object> map = new LinkedHashMap<>();
    map.put("settingsService", settingsService);
    final List<AbstractQuartzJob> jobs = new LinkedList<>();
    jobs.add(dbBackupJob());
    jobs.add(csvExportJob());
    jobs.add(csvImportJob());
    jobs.add(dbMaintenanceJob());
    jobs.add(filesystemCleanupJob());
    map.put("jobs", jobs);
    factory.setSchedulerContextAsMap(map);
    factory.setTriggers(new Trigger[] {cronTrigger});
    return factory;
    }
    }

    今天搜索了很多为什么调度程序任务没有正确关闭......
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak.
    Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak.

    丑陋的黑客是编写 SchedulerFactoryBeanWithShutdownDelay 类。
    public class SchedulerFactoryBeanWithShutdownDelay extends SchedulerFactoryBean {
    private static final int SHUTDOWN_TIMEOUT = 2000;

    @Override
    public void destroy() throws SchedulerException {
    log.debug("Start shutdown of Quartz scheduler factory bean");
    super.destroy();
    try {
    log.debug("wait {}ms to shutdown Quartz", SHUTDOWN_TIMEOUT);
    Thread.sleep(SHUTDOWN_TIMEOUT);
    log.debug("Quartz scheduler shutdown completed");
    } catch (InterruptedException e) {
    log.error("", e);
    }
    }
    }

    但是这个问题应该已经关闭了: https://jira.terracotta.org/jira/browse/QTZ-192

    我犯了错误还是可以确认?

    最佳答案

    excellent article关于 Tomcat 中的内存泄漏。阅读这篇文章,启动您的 Web 应用程序,让 Quartz 作业执行,然后停止 Web 应用程序,然后获取 Tomcat JVM 的堆转储,将堆转储加载到 Eclipse MAT 中并找出哪些类导致内存泄漏。那么你应该能够解决这个问题。

    关于Spring + Quartz = 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24387563/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com