我刚刚开始学习Quartz调度,并且在第一步中我遇到了问题。
我正在其主要网站上查看它的示例,但是当我尝试在自己的工作空间中进行开发时,这给了我错误。
package testing.quartz.scheduler;
import java.util.Date;
import java.util.logging.Logger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
public class TesterMain {
/**
* @param args
*/
public void run() throws Exception {
// First we must get a reference to a scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
// computer a time that is on the next round minute
Date runTime = evenMinuteDate(new Date());<--Here its giving me error
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)<--Here its giving me error
.withIdentity("job1", "group1")
.build();
// Trigger the job to run on the next round minute
Trigger trigger = newTrigger()<--Here its giving me error
.withIdentity("trigger1", "group1")
.startAt(runTime)
.build();
// Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);
// Start up the scheduler (nothing can actually run until the
// scheduler has been started)
sched.start();
// wait long enough so that the scheduler as an opportunity to
// run the job!
try {
// wait 65 seconds to show job
Thread.sleep(65L * 1000L);
// executing...
} catch (Exception e) {
}
// shut down the scheduler
sched.shutdown(true);
}
public static void main(String[] args) throws Exception {
TesterMain example = new TesterMain();
example.run();
}
}
我已经指定了导致编译错误的位置。告诉这些方法在您的课程中不存在。所以我想知道这些方法是否真的有效(newTrigger,newJob,evenMinuteDate)。我很困惑。我已经添加了所有需要的罐子。
最佳答案
它不会编译,因为您忘记了导入正确的类。
这可能会解决它:
import static org.quartz.DateBuilder.*;
import static org.quartz.JobBuilder.*;
import static org.quartz.TriggerBuilder.*;
关于java - 使用Quartz调度作业,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9799945/