本文整理匯總了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);
}
}