Java Code Examples for org.springframework.scheduling.quartz.SchedulerFactoryBean#setStartupDelay()

The following examples show how to use org.springframework.scheduling.quartz.SchedulerFactoryBean#setStartupDelay() . 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: QuartzSchedule.java    From RCT 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 4
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 5
Source File: SchedulerConfig.java    From SpringBoot2.0 with Apache License 2.0 5 votes vote down vote up
@Bean(name = "SchedulerFactory")
public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean bean = new SchedulerFactoryBean();
    bean.setDataSource(dataSource);
    bean.setStartupDelay(5);
    bean.setAutoStartup(true);
    bean.setApplicationContextSchedulerContextKey("applicationContext");
    bean.setConfigLocation(new ClassPathResource("/quartz.properties"));
    return bean;
}
 
Example 6
Source File: ApiBootQuartzAutoConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SchedulerFactoryBean quartzScheduler() {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    SpringBeanJobFactory jobFactory = new SpringBeanJobFactory();
    jobFactory.setApplicationContext(this.applicationContext);
    schedulerFactoryBean.setJobFactory(jobFactory);
    if (this.properties.getSchedulerName() != null) {
        schedulerFactoryBean.setSchedulerName(this.properties.getSchedulerName());
    }

    schedulerFactoryBean.setAutoStartup(this.properties.isAutoStartup());
    schedulerFactoryBean.setStartupDelay((int) this.properties.getStartupDelay().getSeconds());
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(this.properties.isWaitForJobsToCompleteOnShutdown());
    schedulerFactoryBean.setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs());
    if (!this.properties.getProperties().isEmpty()) {
        schedulerFactoryBean.setQuartzProperties(this.asProperties(this.properties.getProperties()));
    }

    if (this.jobDetails != null && this.jobDetails.length > 0) {
        schedulerFactoryBean.setJobDetails(this.jobDetails);
    }

    if (this.calendars != null && !this.calendars.isEmpty()) {
        schedulerFactoryBean.setCalendars(this.calendars);
    }

    if (this.triggers != null && this.triggers.length > 0) {
        schedulerFactoryBean.setTriggers(this.triggers);
    }

    this.customize(schedulerFactoryBean);
    return schedulerFactoryBean;
}
 
Example 7
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;
}
 
Example 8
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 9
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 10
Source File: XxlJobDynamicSchedulerConfig.java    From zuihou-admin-boot 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 11
Source File: SchedulerConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
@Override
public void customize(SchedulerFactoryBean schedulerFactoryBean) {
    //延时5秒启动
    schedulerFactoryBean.setStartupDelay(5);
    schedulerFactoryBean.setAutoStartup(true);
    schedulerFactoryBean.setOverwriteExistingJobs(true);
    // 任务执行日志监听
    schedulerFactoryBean.setGlobalJobListeners(jobLogsListener);
}
 
Example 12
Source File: ScheduleConfig.java    From RuoYi-Vue 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 13
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 14
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 15
Source File: SchedulerConfig.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * Scheduler工厂类
 *
 * @return
 * @throws IOException
 */
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setSchedulerName("Cluster_Scheduler");
    factory.setDataSource(dataSource);
    factory.setApplicationContextSchedulerContextKey("applicationContext");
    factory.setTaskExecutor(schedulerThreadPool());
    factory.setQuartzProperties(quartzProperties());
    factory.setStartupDelay(10);//延迟10s执行
    return factory;
}
 
Example 16
Source File: JobQuartzAutoConfiguration.java    From spring-boot-starter-micro-job with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SchedulerFactoryBean quartzScheduler() {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    SpringBeanJobFactory jobFactory = new SpringBeanJobFactory();
    jobFactory.setApplicationContext(this.applicationContext);
    schedulerFactoryBean.setJobFactory(jobFactory);
    if (this.properties.getSchedulerName() != null) {
        schedulerFactoryBean.setSchedulerName(this.properties.getSchedulerName());
    }

    schedulerFactoryBean.setAutoStartup(this.properties.isAutoStartup());
    schedulerFactoryBean.setStartupDelay((int) this.properties.getStartupDelay().getSeconds());
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(this.properties.isWaitForJobsToCompleteOnShutdown());
    schedulerFactoryBean.setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs());
    if (!this.properties.getProperties().isEmpty()) {
        schedulerFactoryBean.setQuartzProperties(this.asProperties(this.properties.getProperties()));
    }

    if (this.jobDetails != null && this.jobDetails.length > 0) {
        schedulerFactoryBean.setJobDetails(this.jobDetails);
    }

    if (this.calendars != null && !this.calendars.isEmpty()) {
        schedulerFactoryBean.setCalendars(this.calendars);
    }

    if (this.triggers != null && this.triggers.length > 0) {
        schedulerFactoryBean.setTriggers(this.triggers);
    }

    this.customize(schedulerFactoryBean);
    return schedulerFactoryBean;
}
 
Example 17
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 18
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 19
Source File: QuartzSchedulerAutoConfiguration.java    From spring-boot-starter-quartz with Apache License 2.0 4 votes vote down vote up
@Bean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)
@ConditionalOnMissingBean
public SchedulerFactoryBean autoSchedulerFactory(ApplicationContext applicationContext, JobFactory jobFactory,
		@Autowired(required=false) QuartzSchedulerProperties properties,
		@Qualifier(QUARTZ_PROPERTIES_BEAN_NAME) Properties quartzProperties,
		@Autowired(required=false) List<TriggerListener> triggerListeners,
		@Autowired(required=false) List<JobListener> jobListeners,
		@Autowired(required=false) List<SchedulerListener> schedulerListeners) {
	
	if (null == properties) {
		LOGGER.warn("no QuartzSchedulerProperties found, consider to set quartz.enabled=true in properties");
		return null;
	}
	
	LOGGER.debug("creating SchedulerFactory");
	 
       SchedulerFactory factorySettings = properties.getSchedulerFactory();
	SchedulerRepository schedulerRepo = SchedulerRepository.getInstance();
	if (schedulerRepo.remove(QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)) {
		LOGGER.debug("removed scheduler from SchedulerRepository with name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME);
	}
	if (null != factorySettings.getSchedulerName() && schedulerRepo.remove(factorySettings.getSchedulerName())) {
		LOGGER.debug("removed scheduler from SchedulerRepository with name: " + factorySettings.getSchedulerName());
	}
	
	SchedulerFactoryBean factory = BeanUtils.instantiateClass(SchedulerFactoryBean.class);
	
       factory.setApplicationContext(applicationContext);
       factory.setJobFactory(jobFactory);
       
       Persistence persistenceSettings = properties.getPersistence();
       if (persistenceSettings.isPersisted()) {
       	factory.setDataSource(getDataSource(applicationContext, persistenceSettings));
       	if (persistenceSettings.isUsePlatformTxManager()) {
       		PlatformTransactionManager txManager = getTransactionManager(applicationContext, persistenceSettings.getPlatformTxManagerBeanName());
           	if (null != txManager) {
               	factory.setTransactionManager(txManager);
               }
       	}
       }
       
       if (!StringUtils.isEmpty(factorySettings.getSchedulerName())) {
       	factory.setSchedulerName(factorySettings.getSchedulerName());
       } else {
       	LOGGER.debug("no SchedulerName configured, using bean name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME);
       }
       factory.setPhase(factorySettings.getPhase());
       factory.setStartupDelay(factorySettings.getStartupDelay());
       factory.setAutoStartup(factorySettings.isAutoStartup());
       factory.setWaitForJobsToCompleteOnShutdown(factorySettings.isWaitForJobsToCompleteOnShutdown());
       factory.setOverwriteExistingJobs(factorySettings.isOverwriteExistingJobs());
       factory.setExposeSchedulerInRepository(factorySettings.isExposeSchedulerInRepository());
       
       factory.setQuartzProperties(quartzProperties);
       
       if (!CollectionUtils.isEmpty(jobListeners)) {
       	LOGGER.info("configuring " + jobListeners.size() + " job listeners");
       	factory.setGlobalJobListeners(jobListeners.toArray(new JobListener[]{}));
       }
       if (!CollectionUtils.isEmpty(triggerListeners)) {
       	LOGGER.info("configuring " + triggerListeners.size() + " trigger listeners");
       	factory.setGlobalTriggerListeners(triggerListeners.toArray(new TriggerListener[]{}));
       }
       if (!CollectionUtils.isEmpty(schedulerListeners)) {
       	LOGGER.info("configuring " + schedulerListeners.size() + " scheduler listeners");
       	factory.setSchedulerListeners(schedulerListeners.toArray(new SchedulerListener[]{}));
       }
       
       Collection<Trigger> triggers = getTriggers(applicationContext);
       if (null != triggers && !triggers.isEmpty()) {
       	factory.setTriggers(triggers.toArray(new Trigger[triggers.size()]));
       	LOGGER.info("staring scheduler factory with " + triggers.size() + " job triggers");
       } else {
       	LOGGER.info("staring scheduler factory with 0 job triggers");
       }
       
       QuartzSchedulerFactoryOverrideHook hook = getQuartzSchedulerFactoryOverrideHook(applicationContext);
       if (null != hook) {
       	factory = hook.override(factory, properties, quartzProperties);
       }
       
	return factory;
}
 
Example 20
Source File: QuartzConfig.java    From spring-boot-demo-all with Apache License 2.0 4 votes vote down vote up
@Override
public void customize(SchedulerFactoryBean schedulerFactoryBean) {
    schedulerFactoryBean.setStartupDelay(2);
    schedulerFactoryBean.setAutoStartup(true);
    schedulerFactoryBean.setOverwriteExistingJobs(true);
}