本文整理汇总了Java中org.quartz.Job类的典型用法代码示例。如果您正苦于以下问题:Java Job类的具体用法?Java Job怎么用?Java Job使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Job类属于org.quartz包,在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleJob
import org.quartz.Job; //导入依赖的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;
}
示例2: schedule
import org.quartz.Job; //导入依赖的package包/类
protected <T extends Job> void schedule(final Class<T> reference, final Map<String, Object> jobMap)
throws JobExecutionException {
@SuppressWarnings("unchecked")
T jobInstance = (T) ApplicationContextProvider.getBeanFactory().
createBean(reference, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
String jobName = getClass().getName() + UUID.randomUUID();
jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);
JobBuilder jobDetailBuilder = JobBuilder.newJob(reference).
withIdentity(jobName).
usingJobData(new JobDataMap(jobMap));
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().
withIdentity(JobNamer.getTriggerName(jobName)).
startNow();
try {
scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
} catch (SchedulerException e) {
throw new JobExecutionException("Could not schedule, aborting", e);
}
}
示例3: addSchedule
import org.quartz.Job; //导入依赖的package包/类
/**
* 增加一个调度任务(cron版)
*
* @param name
* 任务名称
* @param job
* 执行内容
* @param cronExpression
* cron表达式
* @throws SchedulerException
*/
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
throws SchedulerException {
Scheduler sched = SF.getScheduler();
JobBuilder builder = JobBuilder.newJob(task);
builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
if (param != null) {
builder.usingJobData(param);
}
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
sched.scheduleJob(builder.build(), trigger);
if (!sched.isShutdown())
sched.start();
return trigger;
}
示例4: interrupt
import org.quartz.Job; //导入依赖的package包/类
/**
* Interrupt the identified InterruptableJob executing in this Scheduler instance.
*
* <p>
* This method is not cluster aware. That is, it will only interrupt
* instances of the identified InterruptableJob currently executing in this
* Scheduler instance, not across the entire cluster.
* </p>
*
* @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
*/
public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobException {
List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
Job job = null;
for(JobExecutionContext jec : jobs) {
if (jec.getFireInstanceId().equals(fireInstanceId)) {
job = jec.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob)job).interrupt();
return true;
} else {
throw new UnableToInterruptJobException(
"Job " + jec.getJobDetail().getKey() +
" can not be interrupted, since it does not implement " +
InterruptableJob.class.getName());
}
}
}
return false;
}
示例5: create
import org.quartz.Job; //导入依赖的package包/类
@Override
public void create(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
Class<? extends Job> jobClass = null;
try {
jobClass = (Class<? extends Job>) Class.forName(scheduleJob.getJobClassName());
} catch (ClassNotFoundException e) {
throw new SchedulerException(e);
}
if (null != jobClass) {
JobDetail jobDetail = JobBuilder.newJob(jobClass)
.withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroupName())
.withDescription(scheduleJob.getJobDescription()).build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(scheduleJob.getTriggerName(), scheduleJob.getTriggerGroupName())
.withDescription(scheduleJob.getTriggerDescription())
.withSchedule(CronScheduleBuilder.cronSchedule(scheduleJob.getTriggerCronExpression())).startNow()
.build();
scheduler.scheduleJob(jobDetail, trigger);
}
}
示例6: newJob
import org.quartz.Job; //导入依赖的package包/类
public Job newJob(TriggerFiredBundle bundle, Scheduler Scheduler) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class<? extends Job> jobClass = jobDetail.getJobClass();
try {
if(log.isDebugEnabled()) {
log.debug(
"Producing instance of Job '" + jobDetail.getKey() +
"', class=" + jobClass.getName());
}
return jobClass.newInstance();
} catch (Exception e) {
SchedulerException se = new SchedulerException(
"Problem instantiating class '"
+ jobDetail.getJobClass().getName() + "'", e);
throw se;
}
}
示例7: JobExecutionContextImpl
import org.quartz.Job; //导入依赖的package包/类
/**
* <p>
* Create a JobExcecutionContext with the given context data.
* </p>
*/
public JobExecutionContextImpl(Scheduler scheduler,
TriggerFiredBundle firedBundle, Job job) {
this.scheduler = scheduler;
this.trigger = firedBundle.getTrigger();
this.calendar = firedBundle.getCalendar();
this.jobDetail = firedBundle.getJobDetail();
this.job = job;
this.recovering = firedBundle.isRecovering();
this.fireTime = firedBundle.getFireTime();
this.scheduledFireTime = firedBundle.getScheduledFireTime();
this.prevFireTime = firedBundle.getPrevFireTime();
this.nextFireTime = firedBundle.getNextFireTime();
this.jobDataMap = new JobDataMap();
this.jobDataMap.putAll(jobDetail.getJobDataMap());
this.jobDataMap.putAll(trigger.getJobDataMap());
}
示例8: newJob
import org.quartz.Job; //导入依赖的package包/类
public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class jobClass = jobDetail.getJobClass();
try {
if(log.isDebugEnabled()) {
log.debug(
"Producing instance of Job '" + jobDetail.getFullName() +
"', class=" + jobClass.getName());
}
return (Job) jobClass.newInstance();
} catch (Exception e) {
SchedulerException se = new SchedulerException(
"Problem instantiating class '"
+ jobDetail.getJobClass().getName() + "'", e);
throw se;
}
}
示例9: prvateAddQuartz
import org.quartz.Job; //导入依赖的package包/类
private boolean prvateAddQuartz(Class<? extends Job> jobClass,JobKey jobKey, CronScheduleBuilder builder, SimpleScheduleBuilder repeatForever) {
if(scheduler==null){
init();
}
//创建一个任务计划生成器 设置任务名称与分组 创建任务计划
JobDetail job = JobBuilder.newJob(jobClass).withIdentity(jobKey).build();
//创建一个触发生成器 设置触发器名称与分组 设置触发器出发条件 创建触发器
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jobKey.getName(),jobKey.getGroup()).withSchedule(builder==null?repeatForever:builder).build();
try {
scheduler.scheduleJob(job, trigger);
outLog("添加任务计划成功!");
return true;
} catch (SchedulerException e) {
outLog("添加任务计划失败!");
}
return false;
}
示例10: schedule
import org.quartz.Job; //导入依赖的package包/类
/**
* Schedule a new process (bundle) to run immediately in the background with the specified Job
* implementation.
*
* This will create a new record in AD_PROCESS_REQUEST.
*
* @param bundle
* The bundle with all of the process' details
* @param jobClass
* The Quartz Job implementation that will execute when
*
* @throws SchedulerException
* If something goes wrong.
*/
public void schedule(ProcessBundle bundle, Class<? extends Job> jobClass)
throws SchedulerException, ServletException {
if (bundle == null) {
throw new SchedulerException("Process bundle cannot be null.");
}
final String requestId = SequenceIdData.getUUID();
final String processId = bundle.getProcessId();
final String channel = bundle.getChannel().toString();
final ProcessContext context = bundle.getContext();
ProcessRequestData.insert(getConnection(), context.getOrganization(), context.getClient(),
context.getUser(), context.getUser(), requestId, processId, context.getUser(), SCHEDULED,
channel.toString(), context.toString(), bundle.getParamsDeflated(), null, null, null, null);
if (bundle.getGroupInfo() != null) {
// Is Part of a Group, update the info
ProcessRequestData.updateGroup(getConnection(), bundle.getGroupInfo().getRequest().getId(),
requestId);
}
schedule(requestId, bundle, jobClass);
}
示例11: findJobs
import org.quartz.Job; //导入依赖的package包/类
<T> void findJobs( @Observes @WithAnnotations({Cron.class}) ProcessAnnotatedType<T> pat, BeanManager beanManager )
{
// Ensure we are named otherwise job won't fire as we can't locate it
AnnotatedType<?> type = pat.getAnnotatedType();
Class<?> clazz = type.getJavaClass();
CDIUtils.addTypeAnnotation( pat, Named.class, () -> new NamedImpl( "Schedule_" + (id++) ) );
if( type.isAnnotationPresent( Cron.class ) ) {
if( Job.class.isAssignableFrom( clazz ) ) {
jobClasses.add( clazz );
}
else {
throw new UnsupportedOperationException( "@Cron on type must implement Job" );
}
}
else {
for( AnnotatedMethod<?> meth: type.getMethods() ) {
if( meth.isAnnotationPresent( Cron.class ) ) {
jobClasses.add( clazz );
}
}
}
}
示例12: schedule
import org.quartz.Job; //导入依赖的package包/类
private void schedule( String expr, String name, Class<? extends Job> jobClass, JobDataMap m )
throws SchedulerException
{
JobDataMap map = m == null ? new JobDataMap() : m;
map.put( "bean", name );
String uid = name + ":" + (jid++);
Trigger trigger = TriggerBuilder.newTrigger()
.withSchedule( CronScheduleBuilder.cronSchedule( expr ) )
.withIdentity( uid )
.build();
JobDetail detail = JobBuilder.newJob()
.ofType( jobClass )
.withIdentity( uid )
.usingJobData( map )
.build();
scheduler.scheduleJob( detail, trigger );
LOG.log( Level.INFO, () -> "Scheduled " + name + " with cron " + expr );
}
示例13: execute
import org.quartz.Job; //导入依赖的package包/类
@Override
public void execute( JobExecutionContext context )
throws JobExecutionException
{
JobDetail d = context.getJobDetail();
JobDataMap m = d.getJobDataMap();
String name = m.getString( "bean" );
LOG.log( Level.INFO, () -> "name " + name );
Bean<?> bean = CDIUtils.getBean( name );
LOG.log( Level.INFO, () -> "bean " + bean );
@SuppressWarnings( "unchecked" )
Job job = CDIUtils.getInstance( (Bean<Job>) bean, Job.class );
LOG.log( Level.INFO, () -> "job " + job );
job.execute( context );
}
示例14: newJob
import org.quartz.Job; //导入依赖的package包/类
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
Preconditions.checkNotNull(applicationContext, "applicationContext cannot be null, should call setApplicationContext first.");
Job job = null;
try {
for (Job each : applicationContext.getBeansOfType(Job.class).values()) {
if (AopUtils.getTargetClass(each) == bundle.getJobDetail().getJobClass()) {
job = each;
break;
}
}
if (null == job) {
throw new NoSuchBeanDefinitionException("");
}
} catch (final BeansException ex) {
log.info("Elastic job: cannot found bean for class: '{}'. This job is not managed for spring.", bundle.getJobDetail().getJobClass().getCanonicalName());
return super.newJob(bundle, scheduler);
}
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.putAll(scheduler.getContext());
jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
jobDataMap.putAll(bundle.getTrigger().getJobDataMap());
Job target = (Job) AopTargetUtils.getTarget(job);
setBeanProps(target, jobDataMap);
return target;
}
示例15: newJob
import org.quartz.Job; //导入依赖的package包/类
@Override
public Job newJob(TriggerFiredBundle arg0, Scheduler arg1) throws SchedulerException {
JobDataMap data = arg0.getJobDetail().getJobDataMap();
ExecutionRunnable task;
Execution execution;
if(data.containsKey(Executor.EXECUTION_ID)) {
String executionID = data.getString(Executor.EXECUTION_ID);
execution = context.getExecutionAccessor().get(executionID);
} else {
String executionTaskID = data.getString(Executor.EXECUTION_TASK_ID);
ExecutionParameters executionParams = (ExecutionParameters) data.get(Executor.EXECUTION_PARAMETERS);
execution = executionRunnableFactory.createExecution(executionParams, executionTaskID);
}
task = executionRunnableFactory.newExecutionRunnable(execution);
ExecutionJob job = new ExecutionJob(task);
return job;
}