Reputation: 2759
I'm creating my first scheduled task in Quartz. For my project I need to store the data in the database.
For starting the scheduler I use:
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
I created a simple job for testing the scheduling
package com.atlascopco.framework.schedule.jobs;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class StoredProcedureJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("test");
}
}
In my database I created some record manually. JOB_DETAILS
SCHED_NAME JOB_NAME JOB_GROUP DESCRIPTION JOB_CLASS_NAME IS_DURABLE IS_NONCONCURRENT IS_UPDATE_DATA REQUESTS_RECOVERY JOB_DATA
test test test test com.atlascopco.framework.schedule.jobs.StoredProcedureJob 1 1 1 1 NULL
TRIGGERS
SCHED_NAME TRIGGER_NAME TRIGGER_GROUP JOB_NAME JOB_GROUP DESCRIPTION NEXT_FIRE_TIME PREV_FIRE_TIME PRIORITY TRIGGER_STATE TRIGGER_TYPE START_TIME END_TIME CALENDAR_NAME MISFIRE_INSTR JOB_DATA
test test test test test test 1477559872000 NULL NULL WAITING SIMPLE 1477559872000 NULL NULL NULL NULL
SIMPLE_TRIGGERS
SCHED_NAME TRIGGER_NAME TRIGGER_GROUP REPEAT_COUNT REPEAT_INTERVAL TIMES_TRIGGERED
test test test 10 1000 0
Now when I start my application the scheduler start. On regular time the log of the scheduler is adding new lines (no error only debug messages). What do I wrong to start the job?
Also when I'm doing scheduler.getTriggerGroupNames()
the list is empty.
Upvotes: 0
Views: 766
Reputation: 2759
Found a way to save the jobs in the database using the API of Quartz
JobDetail jobDetail = JobBuilder.newJob(StoredProcedureJob.class)
.withIdentity("dataJob", "dataJobGroup")
.storeDurably(true)
.requestRecovery(true)
.build();
SimpleTrigger trigger = (SimpleTrigger) newTrigger()
.withIdentity("trigger1", "dataJobGroup")
.startNow()
.withSchedule(
simpleSchedule().withIntervalInSeconds(1)
.repeatForever()).build();
scheduler.scheduleJob(jobDetail, trigger);
Upvotes: 0