Java Code Examples for org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean#setName()

The following examples show how to use org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuartzConfigration.java    From springBoot-study with Apache License 2.0 6 votes vote down vote up
@Bean(name = "jobDetail")  
public MethodInvokingJobDetailFactoryBean detailFactoryBean(ScheduleTask task) {
    // ScheduleTask为需要执行的任务  
    MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();  
    /* 
     *  是否并发执行 
     *  例如每5s执行一次任务,但是当前任务还没有执行完,就已经过了5s了, 
     *  如果此处为true,则下一个任务会bing执行,如果此处为false,则下一个任务会等待上一个任务执行完后,再开始执行 
     */  
    jobDetail.setConcurrent(true);  

    jobDetail.setName("scheduler");// 设置任务的名字  
    jobDetail.setGroup("scheduler_group");// 设置任务的分组,这些属性都可以存储在数据库中,在多任务的时候使用  

    /* 
     * 这两行代码表示执行task对象中的scheduleTest方法。定时执行的逻辑都在scheduleTest。
     */  
    jobDetail.setTargetObject(task);  

    jobDetail.setTargetMethod("scheduleTest");  
    return jobDetail;  
}
 
Example 2
Source File: JobAdder.java    From quartz-glass with Apache License 2.0 6 votes vote down vote up
private JobDetail methodExecuteJobDetail(Class<?> clazz, JobKey jobKey, JobDataMap jobDataMapping) throws Exception {
    MethodInvokingJobDetailFactoryBean factoryBean = new MethodInvokingJobDetailFactoryBean();
    factoryBean.setGroup(jobKey.getGroup());
    factoryBean.setName(jobKey.getName());

    factoryBean.setTargetClass(clazz);
    factoryBean.setTargetMethod(findExecuteMethod(clazz));
    boolean allowConcurrent = !clazz.isAnnotationPresent(DisallowConcurrentExecution.class);
    factoryBean.setConcurrent(allowConcurrent);

    factoryBean.afterPropertiesSet();

    JobDetail jobDetail = factoryBean.getObject();
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    jobDataMap.putAll(jobDataMapping);
    jobDataMap.remove("methodInvoker");

    PojoJobMeta pojoJobMeta = createPojoJobMeta(clazz, jobKey, jobDataMapping);
    jobDataMap.put(GlassConstants.POJO_JOB_META, pojoJobMeta);

    return jobDetail;
}
 
Example 3
Source File: RecoverScheduledJob.java    From distributed-transaction-process with MIT License 5 votes vote down vote up
/**
 * 初始化方法,Spring启动时执行.
 */
public void init() {

    try {
    	// MethodInvokingJobDetailFactoryBean 负责生成具体的任务,只需要指定某个对象的某个方法,在触发器触发时,即调用指定对象的指定方法。
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 指定该任务对应的调用对象,这个对象所属的类无需实现任何接口
        jobDetail.setTargetObject(transactionRecovery);
        // 指定在targetObject对象中某个的方法(此处调用TransactionRecovery中的startRecover方法)
        jobDetail.setTargetMethod("startRecover");
        // 设置任务名称
        jobDetail.setName("transactionRecoveryJob");
        // 是否允许任务并发执行,类默认是并发执行的,这时候如果不设置“concurrent”为false,很可能带来并发或者死锁的问题,而且几率较小,不容易复现,
        // 设置为false表示等上一个任务执行完后再开启新的任务
        jobDetail.setConcurrent(false);
        jobDetail.afterPropertiesSet();

        // 触发器生成器类,用被指定的调度器调度生成指定规则的触发器对象
        // 该类负责在spring容器中创建一个触发器,该类的ID应该在SchedulerFactoryBean属性的List中被引用,这样这个触发器才能保证被某个指定调度器调度
        CronTriggerFactoryBean cronTrigger = new CronTriggerFactoryBean();
        // 设置触发器名称
        cronTrigger.setBeanName("transactionRecoveryCronTrigger");
        // 触发规则(这里通过事务配置器获取事务恢复定时任务规则)
        cronTrigger.setCronExpression(transactionConfigurator.getRecoverConfig().getCronExpression());
        cronTrigger.afterPropertiesSet();

        // 设置调度任务
        scheduler.scheduleJob(jobDetail.getObject(), cronTrigger.getObject());
        // 启动任务调度器
        scheduler.start();

    } catch (Exception e) {
        throw new SystemException(e);
    }
}
 
Example 4
Source File: GlassJobFactory.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
private MethodInvokingJobDetailFactoryBean createMethodInvoker(PojoJobMeta pojoJobMeta) throws Exception {
    MethodInvokingJobDetailFactoryBean factoryBean = new MethodInvokingJobDetailFactoryBean();
    factoryBean.setGroup(pojoJobMeta.getGroup());
    factoryBean.setName(pojoJobMeta.getName());

    factoryBean.setTargetClass(pojoJobMeta.getTargetClass());
    factoryBean.setTargetMethod(pojoJobMeta.getTargetMethod());
    factoryBean.setConcurrent(pojoJobMeta.isConcurrent());

    factoryBean.afterPropertiesSet();


    return factoryBean;
}