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

The following examples show how to use org.springframework.scheduling.quartz.SchedulerFactoryBean#setApplicationContextSchedulerContextKey() . 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: 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 2
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 3
Source File: Application.java    From quartz-manager with MIT License 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactory(ApplicationContext applicationContext) {
	SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
	AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
	jobFactory.setApplicationContext(applicationContext);
	
	factoryBean.setJobFactory(jobFactory);
	factoryBean.setApplicationContextSchedulerContextKey("applicationContext");
	return factoryBean;
}
 
Example 4
Source File: ScheduleConfig.java    From renren-fast with GNU 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", "RenrenScheduler");
        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("RenrenScheduler");
        //延时启动
        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: 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 6
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 7
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 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 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 10
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 11
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 12
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 13
Source File: ScheduleConfig.java    From kvf-admin 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", "KvfScheduler");
    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 = ?");

    factory.setQuartzProperties(prop);

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

    return factory;
}
 
Example 14
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 15
Source File: ScheduleConfig.java    From ruoyiplus 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 16
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 17
Source File: XxlJobDynamicSchedulerConfig.java    From microservices-platform 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: FebsJobConfigure.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    // 设置数据源
    DataSource job = dynamicRoutingDataSource.getDataSource("job");
    factory.setDataSource(job);
    Properties prop = new Properties();
    // 任务调度实例名称,集群时多个实例名称保持一致
    prop.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "FebsCloudScheduler");
    // 任务调度实例ID,指定为AUTO时,将自动生成ID
    prop.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, StdSchedulerFactory.AUTO_GENERATE_INSTANCE_ID);
    // quartz提供的简单线程池,适用于绝大部分场景
    prop.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class);
    // 并发执行任务的线程数,取决于服务器系统资源
    prop.put("org.quartz.threadPool.threadCount", "20");
    // 可以是Thread.MIN_PRIORITY(1)和Thread.MAX_PRIORITY(10)之间的任何int值 。
    // 默认值为Thread.NORM_PRIORITY(5)
    prop.put("org.quartz.threadPool.threadPriority", "5");
    // 指定任务存储策略,这里使用关系型数据库
    prop.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, JobStoreTX.class);
    // 是否开启集群
    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("FEBS_Cloud_Scheduler");
    // 延时启动
    factory.setStartupDelay(1);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    // 启动时更新己存在的 Job
    factory.setOverwriteExistingJobs(true);
    // 设置自动启动,默认为 true
    factory.setAutoStartup(true);
    return factory;
}
 
Example 19
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 20
Source File: ScheduleConfig.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 4 votes vote down vote up
@Bean
@DependsOn("flywayConfig") // 这里指定依赖于 flywayConfig 类
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
{
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setDataSource(dataSource);

    // quartz参数
    Properties prop = new Properties();
    prop.put("org.quartz.scheduler.instanceName", "LuckyFrameScheduler");
    prop.put("org.quartz.scheduler.instanceId", "AUTO");
    // 线程池配置
    prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    prop.put("org.quartz.threadPool.threadCount", "50");
    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("LuckyFrameScheduler");
    // 延时启动
    factory.setStartupDelay(1);
    factory.setApplicationContextSchedulerContextKey("applicationContextKey");
    // 可选,QuartzScheduler
    // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
    factory.setOverwriteExistingJobs(true);
    // 设置自动启动,默认为true
    factory.setAutoStartup(true);

    return factory;
}