本文整理汇总了Java中org.quartz.CronTrigger类的典型用法代码示例。如果您正苦于以下问题:Java CronTrigger类的具体用法?Java CronTrigger怎么用?Java CronTrigger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CronTrigger类属于org.quartz包,在下文中一共展示了CronTrigger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRunningJob
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* 所有正在运行的job
*
* @return
* @throws SchedulerException
*/
public List<ScheduleJob> getRunningJob() throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
List<ScheduleJob> jobList = new ArrayList<ScheduleJob>(executingJobs.size());
for (JobExecutionContext executingJob : executingJobs) {
ScheduleJob job = new ScheduleJob();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
job.setName(jobKey.getName());
job.setGroup(jobKey.getGroup());
job.setDescription("触发器:" + trigger.getKey());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
job.setStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
job.setCron(cronExpression);
}
jobList.add(job);
}
return jobList;
}
示例2: getAllJob
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* 获取所有计划中的任务列表
*
* @return
* @throws SchedulerException
*/
public List<ScheduleJob> getAllJob() throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
List<ScheduleJob> jobList = new ArrayList<ScheduleJob>();
for (JobKey jobKey : jobKeys) {
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
ScheduleJob job = new ScheduleJob();
job.setName(jobKey.getName());
job.setGroup(jobKey.getGroup());
job.setDescription("触发器:" + trigger.getKey());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
job.setStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
job.setCron(cronExpression);
}
jobList.add(job);
}
}
return jobList;
}
示例3: scheduleJob
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* The user may configure this binding to update the internal clock of
* FHT80b devices via rf command. The method takes care of scheduling this
* job.
*/
private JobKey scheduleJob(Class<? extends Job> jobClass, String cronExpression) {
JobKey jobKey = null;
try {
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
JobDetail detail = JobBuilder.newJob(jobClass).withIdentity("FHT "+jobClass.getSimpleName(), "cul").build();
detail.getJobDataMap().put(FHTBinding.class.getName(), this);
CronTrigger trigger = TriggerBuilder.newTrigger().forJob(detail)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
jobKey = detail.getKey();
sched.scheduleJob(detail, trigger);
} catch (SchedulerException e) {
logger.error("Can't schedule time update job", e);
}
return jobKey;
}
示例4: getTrigger
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* Build the cron trigger
*
* @return The trigger
* @throws Exception
*/
public Trigger getTrigger() throws Exception
{
Trigger trigger = new CronTrigger(getBeanName(), Scheduler.DEFAULT_GROUP, getCronExpression());
if (this.startDelay > 0)
{
trigger.setStartTime(new Date(System.currentTimeMillis() + this.startDelay));
}
JobDetail jd = super.getJobDetail();
if (jd != null)
{
String jobName = super.getJobDetail().getKey().getName();
if (jobName != null && !jobName.isEmpty())
{
trigger.setJobName(jobName);
}
String jobGroup = super.getJobDetail().getKey().getGroup();
if (jobGroup != null && !jobGroup.isEmpty())
{
trigger.setJobGroup(jobGroup);
}
}
return trigger;
}
示例5: modifyJobTime
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* @Description: 修改一个任务的触发时间(使用默认的任务组名,触发器名,触发器组名)
* @param jobName
* @param time
*
*/
@SuppressWarnings("unchecked")
public static void modifyJobTime(String jobName, String time) {
TriggerKey triggerKey = TriggerKey.triggerKey(
jobName, TRIGGER_GROUP_NAME);
try {
Scheduler sched = gSchedulerFactory.getScheduler();
CronTrigger trigger =(CronTrigger) sched.getTrigger(triggerKey);
if (trigger == null) {
return;
}
String oldTime = trigger.getCronExpression();
if (!oldTime.equalsIgnoreCase(time)) {
CronScheduleBuilder scheduleBuilder =CronScheduleBuilder.cronSchedule(time);
//按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey)
.withSchedule(scheduleBuilder).build();
//按新的trigger重新设置job执行
sched.rescheduleJob(triggerKey, trigger);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: wrapScheduleJob
import org.quartz.CronTrigger; //导入依赖的package包/类
private void wrapScheduleJob(ScheduleJob scheduleJob,Scheduler scheduler,JobKey jobKey,Trigger trigger){
try {
scheduleJob.setJobName(jobKey.getName());
scheduleJob.setJobGroup(jobKey.getGroup());
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
ScheduleJob job = (ScheduleJob)jobDetail.getJobDataMap().get("scheduleJob");
scheduleJob.setDesc(job.getDesc());
scheduleJob.setJobId(job.getJobId());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
scheduleJob.setJobStatus(triggerState.name());
if(trigger instanceof CronTrigger){
CronTrigger cronTrigger = (CronTrigger)trigger;
String cronExpression = cronTrigger.getCronExpression();
scheduleJob.setCronExpression(cronExpression);
}
} catch (SchedulerException e) {
e.printStackTrace();
}
}
示例7: start
import org.quartz.CronTrigger; //导入依赖的package包/类
public void start(){
for(int index = 0; index < jobList.size(); index++){
JobInfo jobInfo = jobList.get(index);
String logTitle = "[" + code + "]" + jobInfo.getName() + " ";
try{
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
JobDetail job = newJob(DataTask.class).withIdentity("job-" + jobInfo.getName(), code).build();
job.getJobDataMap().put("srcDb", srcDb);
job.getJobDataMap().put("destDb", destDb);
job.getJobDataMap().put("jobInfo", jobInfo);
job.getJobDataMap().put("logTitle", logTitle);
logger.info(jobInfo.getCron());
CronTrigger trigger = newTrigger()
.withIdentity("trigger-" + jobInfo.getName(), code)
.withSchedule(cronSchedule(jobInfo.getCron())).build();
sched.scheduleJob(job, trigger);
sched.start();
}catch(Exception e){
logger.info(logTitle + e.getMessage());
logger.info(logTitle + " run failed");
continue;
}
}
}
示例8: JobRegist
import org.quartz.CronTrigger; //导入依赖的package包/类
public void JobRegist() throws Exception {
Class<?> c = null;
// 등록할 스케줄 정보 설정
setSchList();
for (int j = 0; j < schDTO.length; j++) {
try {
c = Class.forName(schDTO[j].getTask_class());
jobDetail = new JobDetail(schDTO[j].getTask_id(), schDTO[j].getTask_group_id(), c);
trigger = new CronTrigger(schDTO[j].getTask_id(), schDTO[j].getTask_group_id());
trigger.setCronExpression(schDTO[j].getTask_expression());
scheduler.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
throw e;
}
}
}
示例9: insertExtendedTriggerProperties
import org.quartz.CronTrigger; //导入依赖的package包/类
public int insertExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {
CronTrigger cronTrigger = (CronTrigger)trigger;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(Util.rtp(INSERT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
ps.setString(1, trigger.getKey().getName());
ps.setString(2, trigger.getKey().getGroup());
ps.setString(3, cronTrigger.getCronExpression());
ps.setString(4, cronTrigger.getTimeZone().getID());
return ps.executeUpdate();
} finally {
Util.closeStatement(ps);
}
}
示例10: updateExtendedTriggerProperties
import org.quartz.CronTrigger; //导入依赖的package包/类
public int updateExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {
CronTrigger cronTrigger = (CronTrigger)trigger;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(Util.rtp(UPDATE_CRON_TRIGGER, tablePrefix, schedNameLiteral));
ps.setString(1, cronTrigger.getCronExpression());
ps.setString(2, cronTrigger.getTimeZone().getID());
ps.setString(3, trigger.getKey().getName());
ps.setString(4, trigger.getKey().getGroup());
return ps.executeUpdate();
} finally {
Util.closeStatement(ps);
}
}
示例11: getScheduleBuilder
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* Get a {@link ScheduleBuilder} that is configured to produce a
* schedule identical to this trigger's schedule.
*
* @see #getTriggerBuilder()
*/
@Override
public ScheduleBuilder<CronTrigger> getScheduleBuilder() {
CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule(getCronExpression())
.inTimeZone(getTimeZone());
switch(getMisfireInstruction()) {
case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing();
break;
case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed();
break;
}
return cb;
}
示例12: toCompositeData
import org.quartz.CronTrigger; //导入依赖的package包/类
public static CompositeData toCompositeData(CronTrigger trigger) {
try {
return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
new Object[] {
trigger.getCronExpression(),
trigger.getTimeZone(),
trigger.getKey().getName(),
trigger.getKey().getGroup(),
trigger.getJobKey().getName(),
trigger.getJobKey().getGroup(),
trigger.getDescription(),
JobDataMapSupport.toTabularData(trigger
.getJobDataMap()),
trigger.getCalendarName(),
((OperableTrigger)trigger).getFireInstanceId(),
trigger.getMisfireInstruction(),
trigger.getPriority(), trigger.getStartTime(),
trigger.getEndTime(), trigger.getNextFireTime(),
trigger.getPreviousFireTime(),
trigger.getFinalFireTime() });
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
示例13: insertCronTrigger
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* <p>
* Insert the cron trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows inserted
*/
public int insertCronTrigger(Connection conn, CronTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_CRON_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setString(3, trigger.getCronExpression());
ps.setString(4, trigger.getTimeZone().getID());
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例14: updateCronTrigger
import org.quartz.CronTrigger; //导入依赖的package包/类
/**
* <p>
* Update the cron trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows updated
*/
public int updateCronTrigger(Connection conn, CronTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_CRON_TRIGGER));
ps.setString(1, trigger.getCronExpression());
ps.setString(2, trigger.getName());
ps.setString(3, trigger.getGroup());
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例15: addJobTrigger
import org.quartz.CronTrigger; //导入依赖的package包/类
@Transactional
@Override
public boolean addJobTrigger(ScheduleJobEntity job) {
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = newTrigger()
.forJob(job.getJobKey()) //绑定job
.withIdentity(job.getTriggerKey())
.startAt(job.getStartDate()) // job开始日期
.endAt(job.getEndDate())// job结束日期
.withSchedule(scheduleBuilder).build();
// 将trigger添加到quartz的scheduler容器
scheduler.scheduleJob(trigger);
return Boolean.TRUE;
} catch (SchedulerException e) {
throw new ServiceException(e);
}
}