我的xml文件
<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data version="2.0"
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_2_0.xsd">
<schedule>
<job>
<name>tryJob</name>
<group>test_group</group>
<job-class>HelloJobB</job-class>
<durability>true</durability>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>testTrigger</name>
<group>test_group</group>
<description>try</description>
<job-name>tryJob</job-name>
<cron-expression>0 57 12 1/1 * ? *</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
和我的属性文件
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.jobFactory.class = org.quartz.simpl.SimpleJobFactory
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.jobFactory.class = org.quartz.simpl.SimpleJobFactory
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.dataSource.quartzDataSource.driver = org.postgresql.Driver
org.quartz.dataSource.quartzDataSource.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.quartzDataSource.user = quartz
org.quartz.dataSource.quartzDataSource.password = mask1234
org.quartz.dataSource.quartzDataSource.maxConnections = 9
和我的主要方法类文件
package quartz;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.simpl.CascadingClassLoadHelper;
import org.quartz.xml.ValidationException;
import org.quartz.xml.XMLSchedulingDataProcessor;
import org.xml.sax.SAXException;
import com.mkyong.io.BufferedReaderExample;
public class JobsWithXML {
public static Scheduler getScheduler() throws SchedulerException{
SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory("server.properties");
Scheduler scheduler = stdSchedulerFactory.getScheduler();
scheduler.start();
return scheduler;
}
public static String readFile(String path) throws IOException{
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(path));
String sCurrentLine = br.readLine();
while (sCurrentLine != null) {
sb.append(sCurrentLine);
sCurrentLine = br.readLine();
}
return sb.toString();
}
public static void main(String[] args) {
CascadingClassLoadHelper clhelper = new CascadingClassLoadHelper();
clhelper.initialize();
XMLSchedulingDataProcessor xmlJobLoader;
try {
xmlJobLoader = new XMLSchedulingDataProcessor(clhelper);
String fileName = JobsWithXML.class.getResource("simpleJobs.xml").getPath();
InputStream inStream = new ByteArrayInputStream(readFile(fileName).getBytes());
String systemId = XMLSchedulingDataProcessor.QUARTZ_SYSTEM_ID_JAR_PREFIX;
Scheduler scheduler = getScheduler();
xmlJobLoader.processStreamAndScheduleJobs(inStream, systemId, scheduler);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XPathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行此main方法时,它总是抛出异常
org.quartz.JobPersistenceException: The job (DEFAULT.tryJob) referenced by the trigger does not exist.
at org.quartz.simpl.RAMJobStore.storeTrigger(RAMJobStore.java:420)
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:886)
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:259)
at org.quartz.xml.XMLSchedulingDataProcessor.scheduleJobs(XMLSchedulingDataProcessor.java:1171)
at org.quartz.xml.XMLSchedulingDataProcessor.processStreamAndScheduleJobs(XMLSchedulingDataProcessor.java:531)
at quartz.JobsWithXML.main(JobsWithXML.java:58)
但是在xml文件中,DEFAULT组不使用那么为什么当我更改作业组名称默认其工作时它总是抛出异常但是在组名中添加任何名称标签其抛出异常为什么
答案 0 :(得分:1)
我认为您在所有schedulers属性中使用相同的数据源名称 您可以为所有调度程序尝试唯一的数据源名称