Java Quartz内存泄漏消息
我的Web应用程序中有一个石英作业,该作业由Servlet启动。当我重新部署我的应用程序时,我收到以下消息
[DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak
同样在生产中,我们有一个问题,就是tomcat-
server在./shutdown.sh之后不会停止,因此我们必须终止该进程。我认为这取决于石英工作,这是无法停止的。
如何通过重新部署应用程序或关闭服务器来停止石英作业?
我用tomcat 7,石英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 = XYZJoborg.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内存泄漏消息 的全部内容, 来源链接: utcz.com/qa/417018.html