gpt4 book ai didi

Java Quartz 内存泄漏消息

转载 作者:搜寻专家 更新时间:2023-11-01 01:53:42 25 4
gpt4 key购买 nike

我的 Web 应用程序中有一个 quartz 作业,它由一个 servlet 启动。当我重新部署我的应用程序时,我收到以下消息

[DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak

同样在生产中,我们遇到了 tomcat 服务器在 ./shutdown.sh 之后没有停止的问题,因此我们必须终止该进程。在我看来,它依赖于 quartz 作业,不能停止。

如何通过重新部署我的应用程序或关闭服务器来停止 quartz 作业?

我用的是tomcat 7,quartz 2.1.6 ...

    SchedulerFactory sf = new StdSchedulerFactory();

Scheduler scheduler = sf.getScheduler();

scheduler.start();

JobDetail job = JobBuilder.newJob(XYZJob.class).withIdentity("job1", "group1").build();

Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1","group1")
.startNow()
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 1 * * ?"))
.build();

scheduler.scheduleJob(job, trigger);

如您所见,我的工作每天开始一次。我看不到可以检查标志以取消作业的地方。

最佳答案

我的解决方案是更改我的配置。我创建了一个 quartz.properties

org.quartz.scheduler.instanceName = XYZJob
org.quartz.threadPool.threadCount = 1
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

一个 quartz-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData
http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">

<schedule>
<job>
<name>XYZJob</name>
<group>XYZGroup</group>
<description>Check the contracts idle period</description>
<job-class>com.test.job.cron.XYZJob</job-class>
</job>

<trigger>
<cron>
<name>CronTriggerName</name>
<job-name>XYZJob</job-name>
<job-group>XYZGroup</job-group>
<!-- It will run every day at 1 am -->
<cron-expression>0 0 1 * * ?</cron-expression>
</cron>
</trigger>
</schedule>

并在我的 web.xml 中使用 QuartzInitializerServlet

<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

关闭我的 Tomcat 后,我​​收到以下消息

INFO: QuartzInitializer: Quartz Scheduler successful shutdown.

关于Java Quartz 内存泄漏消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17394541/

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