本文整理匯總了Java中org.quartz.CronExpression類的典型用法代碼示例。如果您正苦於以下問題:Java CronExpression類的具體用法?Java CronExpression怎麽用?Java CronExpression使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
CronExpression類屬於org.quartz包,在下文中一共展示了CronExpression類的38個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: isCronIntervalLessThanMinimum
點讚 5
import org.quartz.CronExpression; //導入依賴的package包/類
/**
* Checks if the given cron expression interval is less or equals to a certain minimum.
*
* @param cronExpression the cron expression to check
*/
public static boolean isCronIntervalLessThanMinimum(String cronExpression) {
try {
// If input is empty or invalid simply return false as default
if (StringUtils.isBlank(cronExpression) || !isValid(cronExpression)) {
return false;
}
CronExpression cron = new CronExpression(cronExpression);
final Date firstExecution = cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
final Date secondExecution = cron.getNextValidTimeAfter(firstExecution);
Minutes intervalMinutes = Minutes.minutesBetween(new DateTime(firstExecution),
new DateTime(secondExecution));
return !intervalMinutes.isGreaterThan(MINIMUM_ALLOWED_MINUTES);
} catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
開發者ID:alancnet,項目名稱:artifactory,代碼行數:24,
示例2: getNextExecutionDate
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
/**
* Retrieves the next execution time based on the schedule and
* the supplied date.
* @param after The date to get the next invocation after.
* @return The next execution time.
*/
public Date getNextExecutionDate(Date after) {
try {
CronExpression expression = new CronExpression(this.getCronPattern());
Date next = expression.getNextValidTimeAfter(DateUtils.latestDate(after, new Date()));
if(next == null) {
return null;
}
else if(endDate != null && next.after(endDate)) {
return null;
}
else {
return next;
}
}
catch(ParseException ex) {
System.out.println(" Encountered ParseException for cron expression: " + this.getCronPattern() + " in schedule: " + this.getOid());
return null;
}
}
開發者ID:DIA-NZ,項目名稱:webcurator,代碼行數:27,
示例3: testSchedule
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
@Test
public void testSchedule() throws Exception{
System.out.println("schedule");
String jobId = "testSchedule_jobId";
CronExpression cronTrigger = new CronExpression("1/1 * * ? * *");
// ZoneId zoneId = ZoneId.of("UTC");
final ConcurrentLinkedDeque invocations = new ConcurrentLinkedDeque<>();
ScheduledJobExecutor jobExec = new ScheduledJobExecutor(){
@Override
public void execute(Map parameters) {
log.info("Test Task executed");
invocations.add(1);
}
};
try{
instance.schedule(jobId, cronTrigger, jobExec);
Thread.sleep(2000l);
assertTrue( invocations.size() > 0 );
}finally{
instance.unSchedule(jobId);
}
}
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:23,
示例4: checkAndSaveSchedule
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
private VmSchedule checkAndSaveSchedule(final VmScheduleVo schedule, final VmSchedule entity) {
// Check the subscription is visible
final Subscription subscription = subscriptionResource.checkVisibleSubscription(schedule.getSubscription());
if (schedule.getCron().split(" ").length == 6) {
// Add the missing "seconds" part
schedule.setCron(schedule.getCron() + " *");
}
// Check expressions first
if (!CronExpression.isValidExpression(schedule.getCron())) {
throw new ValidationJsonException("cron", "vm-cron");
}
// Every second is not accepted
if (schedule.getCron().startsWith("* ")) {
throw new ValidationJsonException("cron", "vm-cron-second");
}
entity.setSubscription(subscription);
entity.setOperation(schedule.getOperation());
entity.setCron(schedule.getCron());
// Persist the new schedules for each provided CRON
vmScheduleRepository.saveAndFlush(entity);
return entity;
}
開發者ID:ligoj,項目名稱:plugin-vm,代碼行數:27,
示例5: add
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
/**
* 注意:@RequestBody需要把所有請求參數作為json解析,因此,不能包含key=value這樣的寫法在請求url中,所有的請求參數都是一個json
*
*/
@RequiresPermissions("job:index")
@ResponseBody
@RequestMapping(value = "job", method = RequestMethod.POST)
public ResponseDTO add(@RequestBody JobAddAO jobAddAO) {
try {
//cron表達式合法性校驗
CronExpression exp = new CronExpression(jobAddAO.getCron());
JobDetailDO jobDetailDO = new JobDetailDO();
BeanUtils.copyProperties(jobAddAO, jobDetailDO);
jobDetailService.addJobDetail(jobDetailDO);
} catch (ParseException e) {
e.printStackTrace();
return new ResponseDTO(0, "failed", null);
}
return new ResponseDTO(1, "success", null);
}
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:22,
示例6: validateCronExpression
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
@RequestMapping("withoutAuth/validateCron.html")
@ResponseBody
public Object validateCronExpression(String cronExpression){
try
{
boolean result = CronExpression.isValidExpression(cronExpression);
if(result)
{
return true;
}else
{
return false;
}
}catch(Exception e)
{
throw new AjaxException(e);
}
}
開發者ID:wjggwm,項目名稱:webside,代碼行數:19,
示例7: nextValidTimeFromCron
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
public static Instant nextValidTimeFromCron(String patterns) {
String[] array = patterns.split("\\|");
Instant next = Instant.MAX;
for (String pattern : array) {
if (pattern.split(" ").length == 5) {
pattern = "0 " + pattern;
}
try {
List parts = Arrays.asList(pattern.split(" "));
if (parts.get(3).equals("*")) {
parts.set(3, "?");
}
CronExpression cronExpression = new CronExpression(parts.stream().collect(Collectors.joining(" ")));
Instant nextPart = cronExpression.getNextValidTimeAfter(Date.from(Instant.now())).toInstant();
next = nextPart.isBefore(next) ? nextPart : next;
} catch (ParseException e) {
log.warn("Could not parse cron expression: {}", e.toString());
}
}
return next;
}
開發者ID:quanticc,項目名稱:ugc-bot-redux,代碼行數:22,
示例8: schedule
點讚 3
import org.quartz.CronExpression; //導入依賴的package包/類
@Override
public void schedule(String jobName, CronExpression