org.springframework.scheduling.quartz.SchedulerFactoryBean Java Examples

The following examples show how to use org.springframework.scheduling.quartz.SchedulerFactoryBean. 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: SchedulerConfig.java    From Almost-Famous with MIT License 7 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    //获取配置属性
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    //创建SchedulerFactoryBean
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    //使用数据源,自定义数据源
    factory.setJobFactory(jobFactory);
    factory.setWaitForJobsToCompleteOnShutdown(true);//这样当spring关闭时,会等待所有已经启动的quartz job结束后spring才能完全shutdown。
    factory.setOverwriteExistingJobs(false);
    factory.setStartupDelay(1);
    return factory;
}
 
Example #2
Source File: RobotScheduledConfig.java    From Almost-Famous with MIT License 6 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    //获取配置属性
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    //在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    //创建SchedulerFactoryBean
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    //使用数据源,自定义数据源
    factory.setJobFactory(jobFactory);
    factory.setWaitForJobsToCompleteOnShutdown(true);//这样当spring关闭时,会等待所有已经启动的quartz job结束后spring才能完全shutdown。
    factory.setOverwriteExistingJobs(false);
    factory.setStartupDelay(1);
    return factory;
}
 
Example #3
Source File: QuartzSchedulerConfig.java    From spring-boot-quartz-demo with MIT License 6 votes vote down vote up
/**
 * create scheduler
 */
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
 
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setQuartzProperties(quartzProperties());
    
    //Register listeners to get notification on Trigger misfire etc
    factory.setGlobalTriggerListeners(triggerListner);
    factory.setGlobalJobListeners(jobsListener);
    
    AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    factory.setJobFactory(jobFactory);
    
    return factory;
}
 
Example #4
Source File: ScheduleAutoConfiguration.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setApplicationContext(applicationContext);
    schedulerFactoryBean.setAutoStartup(schedulerProperties.isAutoStartup());
    schedulerFactoryBean.setDataSource(dataSource);
    schedulerFactoryBean.setTransactionManager(platformTransactionManager);
    schedulerFactoryBean.setOverwriteExistingJobs(schedulerProperties.isOverwriteExistingJobs());
    schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class);
    schedulerFactoryBean.setBeanName(schedulerProperties.getBeanName());
    schedulerFactoryBean.setJobFactory(jobFactory);
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(schedulerProperties.isWaitOnShutdown());
    schedulerFactoryBean.setQuartzProperties(schedulerProperties.getProperties());
    schedulerFactoryBean.setStartupDelay(schedulerProperties.getStartupDelay());
    schedulerFactoryBean.setCalendars(calendarMap);
    schedulerFactoryBean.setSchedulerListeners(schedulerListeners);
    return schedulerFactoryBean;
}
 
Example #5
Source File: QuartzSchedulerConfig.java    From mojito with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the scheduler with triggers/jobs defined in spring beans.
 * <p>
 * The spring beans should use the default group so that it is easy to keep track of new or removed triggers/jobs.
 * <p>
 * In {@link #startScheduler()} triggers/jobs present in Quartz but without a matching spring bean will be
 * removed.
 * <p>
 * Other job and trigger created dynamically must not used the default group else they'll be removed.
 *
 * @return
 * @throws SchedulerException
 */
@Bean
public SchedulerFactoryBean scheduler() throws SchedulerException {

    logger.info("Create SchedulerFactoryBean");

    Properties quartzProperties = quartzPropertiesConfig.getQuartzProperties();

    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();

    String dataSource = quartzProperties.getProperty("org.quartz.jobStore.dataSource");
    schedulerFactory.setQuartzProperties(quartzProperties);
    schedulerFactory.setJobFactory(springBeanJobFactory());
    schedulerFactory.setOverwriteExistingJobs(true);
    schedulerFactory.setTriggers(triggers.toArray(new Trigger[]{}));
    schedulerFactory.setAutoStartup(false);

    return schedulerFactory;
}
 
Example #6
Source File: Admin.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private WebApplicationContext getApplicationContext() {
	if (context == null) {
		String curStep = step; //preserve step
		step = "Shutdown schedulers";
		Long lngId = (long)cfg.getDefaultLangId();
		context = ApplicationHelper.getApplicationContext(lngId);
		SchedulerFactoryBean sfb = context.getBean(SchedulerFactoryBean.class);
		try {
			sfb.getScheduler().shutdown(false);
			step = curStep; //restore
		} catch (Exception e) {
			handleError(e);
		}
	}
	return context;
}
 
Example #7
Source File: AfterHandlingJob.java    From syncope with Apache License 2.0 6 votes vote down vote up
public static void schedule(final SchedulerFactoryBean scheduler, final Map<String, Object> jobMap) {
    @SuppressWarnings("unchecked")
    AfterHandlingJob jobInstance = (AfterHandlingJob) ApplicationContextProvider.getBeanFactory().
            createBean(AfterHandlingJob.class, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
    String jobName = AfterHandlingJob.class.getName() + SecureRandomUtils.generateRandomUUID();

    jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());

    ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);

    JobBuilder jobDetailBuilder = JobBuilder.newJob(AfterHandlingJob.class).
            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) {
        LOG.error("Could not schedule, aborting", e);
    }
}
 
Example #8
Source File: SpringConfig.java    From quartz-glass with Apache License 2.0 6 votes vote down vote up
@Bean
public Scheduler quartzScheduler(ApplicationContext context) throws Exception {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();

    factory.setApplicationContext(context);
    factory.setExposeSchedulerInRepository(true);
    factory.setApplicationContextSchedulerContextKey(APPLICATION_CONTEXT_KEY);
    factory.setJobFactory(glassJobFactory);

    Properties properties = new Properties();
    properties.setProperty("org.quartz.scheduler.skipUpdateCheck","true");
    properties.setProperty("org.quartz.threadPool.class", SimpleThreadPool.class.getName());
    properties.setProperty("org.quartz.threadPool.threadCount", "15");
    properties.setProperty("org.quartz.threadPool.threadPriority", "4");

    if (configuration().isInMemory()) {
        properties.setProperty("org.quartz.jobStore.class", RAMJobStore.class.getName());
    } else {
        factory.setDataSource(dataSource());

        properties.setProperty("org.quartz.jobStore.tablePrefix", configuration().getTablePrefix());
        properties.setProperty("org.quartz.jobStore.isClustered", "false");
        properties.setProperty("org.quartz.jobStore.driverDelegateClass", configuration().getDriverDelegateClass());
    }

    factory.setQuartzProperties(properties);

    factory.afterPropertiesSet();

    Scheduler scheduler = factory.getObject();

    scheduler.getListenerManager().addJobListener(glassJobListener);
    scheduler.getListenerManager().addSchedulerListener(glassSchedulerListener);

    scheduler.start();

    return scheduler;
}
 
Example #9
Source File: SpringQrtzScheduler.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public SchedulerFactoryBean scheduler(Trigger trigger, JobDetail job, DataSource quartzDataSource) {

    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));

    logger.debug("Setting the Scheduler up");
    schedulerFactory.setJobFactory(springBeanJobFactory());
    schedulerFactory.setJobDetails(job);
    schedulerFactory.setTriggers(trigger);

    // Comment the following line to use the default Quartz job store.
    schedulerFactory.setDataSource(quartzDataSource);

    return schedulerFactory;
}
 
Example #10
Source File: QuartzConfigurer.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(SchedulerFactoryBean schedulerFactoryBean) {
    schedulerFactoryBean.setDataSource(dataSource);
    schedulerFactoryBean.setStartupDelay(2);
    schedulerFactoryBean.setAutoStartup(true);
    schedulerFactoryBean.setOverwriteExistingJobs(true);

}
 
Example #11
Source File: SchedulerConfig.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource,
                                                 JobFactory jobFactory) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    factory.setQuartzProperties(quartzConf);
    return factory;
}
 
Example #12
Source File: ScheduleConfig.java    From boot-actuator with MIT License 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    //quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName", "MonitorScheduler");
    prop.put("org.quartz.scheduler.instanceId", "AUTO");
    //线程池配置
    prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount", "20");
    prop.put("org.quartz.threadPool.threadPriority", "5");
    //JobStore配置
    prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
    //集群配置
    prop.put("org.quartz.jobStore.isClustered", "true");
    prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
    prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");

    prop.put("org.quartz.jobStore.misfireThreshold", "12000");
    prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
    factory.setQuartzProperties(prop);

    factory.setSchedulerName("MonitorScheduler");
    //延时启动
    factory.setStartupDelay(30);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    //可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    //设置自动启动,默认为true
    factory.setAutoStartup(true);

    return factory;
}
 
Example #13
Source File: SchedulerConfig.java    From ehousechina with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory, @Qualifier("sampleJobTrigger") Trigger sampleJobTrigger) throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    return factory;
}
 
Example #14
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    scheduler.setTaskExecutor(getAsyncExecutor());
    scheduler.setAutoStartup(true);
    scheduler.setJobFactory(new SimpleJobFactory());
    return scheduler;
}
 
Example #15
Source File: SchedulerConfig.java    From quartz-manager with Apache License 2.0 5 votes vote down vote up
@Bean(name = "scheduler")
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory,
		@Qualifier("jobTrigger") Trigger sampleJobTrigger) throws IOException {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setJobFactory(jobFactory);
	factory.setQuartzProperties(quartzProperties());
	factory.setTriggers(sampleJobTrigger);
	factory.setAutoStartup(false);
	return factory;
}
 
Example #16
Source File: SchedulerConfig.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
  SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
  AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
  jobFactory.setApplicationContext(applicationContext);
  quartzScheduler.setJobFactory(jobFactory);
  return quartzScheduler;
}
 
Example #17
Source File: TestContextConfiguration9.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
@Bean
public QuartzSchedulerFactoryOverrideHook quartzSchedulerFactoryOverrideHook() {
	return new QuartzSchedulerFactoryOverrideHook() {
		
		@Override
		public SchedulerFactoryBean override(SchedulerFactoryBean factory, QuartzSchedulerProperties properties,
				Properties quartzProperties) {
			factory.setTaskExecutor(Executors.newFixedThreadPool(20));
			StaticLog.getInstance().addMessasge(CAPTURE1);
			return factory;
		}
	};
}
 
Example #18
Source File: TestContextConfiguration5.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
@Bean
public QuartzSchedulerFactoryOverrideHook quartzSchedulerFactoryOverrideHook() {
	return new QuartzSchedulerFactoryOverrideHook() {
		
		@Override
		public SchedulerFactoryBean override(SchedulerFactoryBean factory, QuartzSchedulerProperties properties,
				Properties quartzProperties) {
			StaticLog.getInstance().addMessasge(CAPTURE2);
			return factory;
		}
	};
}
 
Example #19
Source File: QuartzJobSchedulerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    // Create scheduler
    SchedulerFactoryBean sfb = new SchedulerFactoryBean();
    sfb.setSchedulerFactoryClass(AlfrescoSchedulerFactory.class);
    sfb.setAutoStartup(false);
    sfb.afterPropertiesSet();
    scheduler = sfb.getScheduler();
    hbJobScheduler = createSimpleJobScheduler();
    hbJobScheduler.setScheduler(scheduler);

}
 
Example #20
Source File: QuartzSchedule.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
@Bean(name = "schedulerFactoryBean")
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    // 延时启动
    factory.setStartupDelay(20);
    // 自定义Job Factory,用于Spring注入
    factory.setJobFactory(jobFactory);
    return factory;
}
 
Example #21
Source File: ScheduleConfig.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    //quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName", "SdbScheduler");
    prop.put("org.quartz.scheduler.instanceId", "AUTO");
    //线程池配置
    prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount", "20");
    prop.put("org.quartz.threadPool.threadPriority", "5");
    //JobStore配置
    prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
    //集群配置
    prop.put("org.quartz.jobStore.isClustered", "true");
    prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
    prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");

    prop.put("org.quartz.jobStore.misfireThreshold", "12000");
    prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
    prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");

    //PostgreSQL数据库,需要打开此注释
    //prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");

    factory.setQuartzProperties(prop);

    factory.setSchedulerName("SdbScheduler");
    //延时启动
    factory.setStartupDelay(30);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    //可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    //设置自动启动,默认为true
    factory.setAutoStartup(scheduleOpen);

    return factory;
}
 
Example #22
Source File: SchedulingUtils.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
public static Scheduler createScheduler(String schedulerName, Executor threaPoolExecutor) throws SchedulerException {
    try {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setSchedulerName(schedulerName);
        schedulerFactoryBean.setTaskExecutor(threaPoolExecutor);
        schedulerFactoryBean.afterPropertiesSet();

        return schedulerFactoryBean.getObject();
    } catch (Exception e) {
        throw new SchedulerException("Unable to create scheduler", e);
    }
}
 
Example #23
Source File: XxlJobDynamicSchedulerConfig.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean getSchedulerFactoryBean(DataSource dataSource) {

    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setDataSource(dataSource);
    schedulerFactory.setAutoStartup(true);                  // 自动启动
    schedulerFactory.setStartupDelay(20);                   // 延时启动,应用启动成功后在启动
    schedulerFactory.setOverwriteExistingJobs(true);        // 覆盖DB中JOB:true、以数据库中已经存在的为准:false
    schedulerFactory.setApplicationContextSchedulerContextKey("applicationContext");
    schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));

    return schedulerFactory;
}
 
Example #24
Source File: ScheduleConfig.java    From FEBS-Security with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setDataSource(dataSource);
	// quartz参数
	Properties prop = new Properties();
	prop.put("org.quartz.scheduler.instanceName", "MyScheduler");
	prop.put("org.quartz.scheduler.instanceId", "AUTO");
	// 线程池配置
	prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
	prop.put("org.quartz.threadPool.threadCount", "20");
	prop.put("org.quartz.threadPool.threadPriority", "5");
	// JobStore配置
	prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
	// 集群配置
	prop.put("org.quartz.jobStore.isClustered", "true");
	prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
	prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");

	prop.put("org.quartz.jobStore.misfireThreshold", "12000");
	prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
	factory.setQuartzProperties(prop);

	factory.setSchedulerName("MyScheduler");
	// 延时启动
	factory.setStartupDelay(1);
	factory.setApplicationContextSchedulerContextKey("applicationContextKey");
	// 可选,QuartzScheduler
	// 启动时更新己存在的 Job,这样就不用每次修改 targetObject后删除 qrtz_job_details表对应记录了
	factory.setOverwriteExistingJobs(true);
	// 设置自动启动,默认为 true
	factory.setAutoStartup(true);

	return factory;
}
 
Example #25
Source File: ScheduleConfig.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    // quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName" , "RuoyiScheduler");
    prop.put("org.quartz.scheduler.instanceId" , "AUTO");
    // 线程池配置
    prop.put("org.quartz.threadPool.class" , "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount" , "20");
    prop.put("org.quartz.threadPool.threadPriority" , "5");
    // JobStore配置
    prop.put("org.quartz.jobStore.class" , "org.quartz.impl.jdbcjobstore.JobStoreTX");
    // 集群配置
    prop.put("org.quartz.jobStore.isClustered" , "true");
    prop.put("org.quartz.jobStore.clusterCheckinInterval" , "15000");
    prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime" , "1");
    prop.put("org.quartz.jobStore.txIsolationLevelSerializable" , "true");

    // sqlserver 启用
    prop.put("org.quartz.jobStore.misfireThreshold" , "12000");
    prop.put("org.quartz.jobStore.tablePrefix" , "QRTZ_");
    factory.setQuartzProperties(prop);

    factory.setSchedulerName("RuoyiScheduler");
    // 延时启动
    factory.setStartupDelay(1);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    // 可选,QuartzScheduler
    // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    // 设置自动启动,默认为true
    factory.setAutoStartup(true);

    return factory;
}
 
Example #26
Source File: XxlJobDynamicSchedulerConfig.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 项目启动时,首先创建【SchedulerFactoryBean】, 然后注入 XxlJobDynamicScheduler,
 * 并执行初始化方法,将【JobRegistryMonitorHelper】、【JobFailMonitorHelper】、【initRpcProvider】初始化
 * JobRegistryMonitorHelper: 注册监控工具类,间隔30秒,
 * JobFailMonitorHelper: 失败监控工具类, 用一个守护线程监控任务执行情况,发生失败时,启动重试机制。 间隔10秒
 *
 * @param schedulerFactory
 * @return
 */
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobDynamicScheduler getXxlJobDynamicScheduler(SchedulerFactoryBean schedulerFactory) {
    Scheduler scheduler = schedulerFactory.getScheduler();

    XxlJobDynamicScheduler xxlJobDynamicScheduler = new XxlJobDynamicScheduler();
    xxlJobDynamicScheduler.setScheduler(scheduler);

    return xxlJobDynamicScheduler;
}
 
Example #27
Source File: ScheduleConfig.java    From supplierShop with MIT License 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
{
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    // quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
    prop.put("org.quartz.scheduler.instanceId", "AUTO");
    // 线程池配置
    prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount", "20");
    prop.put("org.quartz.threadPool.threadPriority", "5");
    // JobStore配置
    prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
    // 集群配置
    prop.put("org.quartz.jobStore.isClustered", "true");
    prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
    prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
    prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");

    // sqlserver 启用
    // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
    prop.put("org.quartz.jobStore.misfireThreshold", "12000");
    prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
    factory.setQuartzProperties(prop);

    factory.setSchedulerName("RuoyiScheduler");
    // 延时启动
    factory.setStartupDelay(1);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    // 可选,QuartzScheduler
    // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    // 设置自动启动,默认为true
    factory.setAutoStartup(true);

    return factory;
}
 
Example #28
Source File: QuartzConfigration.java    From springBoot-study with Apache License 2.0 5 votes vote down vote up
@Bean(name = "scheduler")  
public SchedulerFactoryBean schedulerFactory(Trigger cronJobTrigger) {  
    SchedulerFactoryBean bean = new SchedulerFactoryBean();
    //设置是否任意一个已定义的Job会覆盖现在的Job。默认为false,即已定义的Job不会覆盖现有的Job。
    bean.setOverwriteExistingJobs(true);  
    // 延时启动,应用启动5秒后  ,定时器才开始启动
    bean.setStartupDelay(5);  
    // 注册定时触发器  
    bean.setTriggers(cronJobTrigger);  
    return bean;  
}
 
Example #29
Source File: QuartzScheduleConfig.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    //quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName", schedulerName + "-Scheduler");
    prop.put("org.quartz.scheduler.instanceId", "AUTO");
    //线程池配置
    prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount", "20");
    prop.put("org.quartz.threadPool.threadPriority", "5");
    //JobStore配置
    prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
    //集群配置
    prop.put("org.quartz.jobStore.isClustered", "true");
    prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
    prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");

    prop.put("org.quartz.jobStore.misfireThreshold", "12000");
    prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
    prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");

    //PostgreSQL数据库,需要打开此注释
    //prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");

    factory.setQuartzProperties(prop);

    factory.setSchedulerName(schedulerName + "-Scheduler");
    //延时启动
    factory.setStartupDelay(30);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    //可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    //设置自动启动,默认为true
    factory.setAutoStartup(true);

    return factory;
}
 
Example #30
Source File: ScheduleConfig.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setDataSource(dataSource);

	// quartz参数
	Properties prop = new Properties();
	prop.put("org.quartz.scheduler.instanceName", "AlbedoQuartzScheduler");
	prop.put("org.quartz.scheduler.instanceId", "AUTO");
	// 线程池配置
	prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
	prop.put("org.quartz.threadPool.threadCount", "20");
	prop.put("org.quartz.threadPool.threadPriority", "5");
	// JobStore配置
	prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
	// 集群配置
	prop.put("org.quartz.jobStore.isClustered", "true");
	prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
	prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
	prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");

	// sqlserver 启用
	// prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
	prop.put("org.quartz.jobStore.misfireThreshold", "12000");
	prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
	factory.setQuartzProperties(prop);

	factory.setSchedulerName("AlbedoQuartzScheduler");
	// 延时启动
	factory.setStartupDelay(1);
	factory.setApplicationContextSchedulerContextKey("applicationContextKey");
	// 可选,QuartzScheduler
	// 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
	factory.setOverwriteExistingJobs(true);
	// 设置自动启动,默认为true
	factory.setAutoStartup(true);

	return factory;
}