/** * Starts up this event scheduler. */ @Override public void doStartup() { try { Properties props = new Properties(); props.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, getName()); props.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, getName()); props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); // There should be only one thread here to ensure the proper order of scheduled events. props.put(PROP_THREAD_COUNT, Integer.toString(1)); StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(); schedulerFactory.initialize(props); scheduler = schedulerFactory.getScheduler(); scheduler.start(); } catch (SchedulerException e) { throw SpongeUtils.wrapException(getName(), e); } }
protected Scheduler newScheduler()throws SchedulerException{ StdSchedulerFactory factory=new StdSchedulerFactory(); Properties mergedProps = new Properties(); mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); mergedProps.setProperty("org.quartz.scheduler.instanceName", "BDF2Scheduler"); mergedProps.setProperty("org.quartz.scheduler.instanceId", "CoreBDF2Scheduler"); mergedProps.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", makeSchedulerThreadDaemon); mergedProps.setProperty("org.quartz.threadPool.threadCount", Integer.toString(threadCount)); if (this.configLocation != null) { try { PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation); } catch (IOException e) { e.printStackTrace(); } } factory.initialize(mergedProps); Scheduler scheduler=factory.getScheduler(); Collection<JobExecutionListener> jobListeners = this.getApplicationContext().getBeansOfType(JobExecutionListener.class).values(); for(JobExecutionListener jobListener:jobListeners){ jobListener.setSessionFactory(getSessionFactory()); scheduler.getListenerManager().addJobListener(jobListener); } return scheduler; }
@Provides @Singleton static Scheduler provideScheduler(AuroraCronJobFactory jobFactory) throws SchedulerException { // There are several ways to create a quartz Scheduler instance. This path was chosen as the // simplest to create a Scheduler that uses a *daemon* QuartzSchedulerThread instance. Properties props = new Properties(); String name = "aurora-cron-" + ID_GENERATOR.incrementAndGet(); props.setProperty(PROP_SCHED_NAME, name); props.setProperty(PROP_SCHED_INSTANCE_ID, name); props.setProperty(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getCanonicalName()); props.setProperty(PROP_THREAD_POOL_PREFIX + ".threadCount", NUM_THREADS.get().toString()); props.setProperty(PROP_THREAD_POOL_PREFIX + ".makeThreadsDaemons", Boolean.TRUE.toString()); props.setProperty(PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON, Boolean.TRUE.toString()); Scheduler scheduler = new StdSchedulerFactory(props).getScheduler(); scheduler.setJobFactory(jobFactory); return scheduler; }
public static void initSched(int threadCount) { try { SimpleThreadPool threadPool = new SimpleThreadPool(threadCount, Thread.NORM_PRIORITY); threadPool.initialize(); // create the job store JobStore jobStore = new RAMJobStore(); DirectSchedulerFactory.getInstance().createScheduler(threadPool, jobStore); sched = DirectSchedulerFactory.getInstance().getScheduler(); //init heart sched SimpleThreadPool threadPoolHeart = new SimpleThreadPool(1, Thread.NORM_PRIORITY); threadPoolHeart.initialize(); JobStore jobStoreHeart = new RAMJobStore(); DirectSchedulerFactory.getInstance().createScheduler("HeartScheduler", "SIMPLE_NON_CLUSTERED", threadPoolHeart, jobStoreHeart); heartSched = DirectSchedulerFactory.getInstance().getScheduler("HeartScheduler"); } catch (Exception e) { log.error("error init sched", e); } }
@Override public void start() throws Exception { if (!started) { System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true"); DirectSchedulerFactory factory = DirectSchedulerFactory.getInstance(); SimpleThreadPool threadPool = new SimpleThreadPool(this.numThreads, Thread.NORM_PRIORITY); threadPool.setThreadNamePrefix("scheduling-worker"); threadPool.initialize(); final String schedulerName = DEFAULT_SCHEDULER_NAME + ":" + this.name; factory.createScheduler(schedulerName, DEFAULT_INSTANCE_ID + ":" + this.name, threadPool, new RAMJobStore()); this.scheduler = factory.getScheduler(schedulerName); this.scheduler.getListenerManager().addTriggerListener(new TriggerListener()); this.scheduler.start(); started = true; log.info("Quartz started"); } }
private Properties getQuartzProperties() { Properties result = new Properties(); result.put("org.quartz.threadPool.class", SimpleThreadPool.class.getName()); result.put("org.quartz.threadPool.threadCount", Integer.toString(Runtime.getRuntime().availableProcessors() * 2)); result.put("org.quartz.scheduler.instanceName", "ELASTIC_JOB_CLOUD_TRANSIENT_PRODUCER"); result.put("org.quartz.plugin.shutdownhook.class", ShutdownHookPlugin.class.getName()); result.put("org.quartz.plugin.shutdownhook.cleanShutdown", Boolean.TRUE.toString()); return result; }
private Properties getQuartzProperties() { Properties result = new Properties(); result.put("org.quartz.threadPool.class", SimpleThreadPool.class.getName()); result.put("org.quartz.threadPool.threadCount", Integer.toString(1)); result.put("org.quartz.scheduler.instanceName", "ELASTIC_JOB_CLOUD_STATISTICS_SCHEDULER"); result.put("org.quartz.plugin.shutdownhook.class", ShutdownHookPlugin.class.getName()); result.put("org.quartz.plugin.shutdownhook.cleanShutdown", Boolean.TRUE.toString()); return result; }
/** * Creates an in memory job store (<code>{@link RAMJobStore}</code>) * The thread priority is set to Thread.NORM_PRIORITY * * @param maxThreads * The number of threads in the thread pool * @throws SchedulerException * if initialization failed. */ public void createVolatileScheduler(int maxThreads) throws SchedulerException { SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, Thread.NORM_PRIORITY); threadPool.initialize(); JobStore jobStore = new RAMJobStore(); this.createScheduler(threadPool, jobStore); }
private void initDetectionScheduler() throws Exception{ StdSchedulerFactory factory=new StdSchedulerFactory(); Properties mergedProps = new Properties(); mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); mergedProps.setProperty("org.quartz.scheduler.instanceName", "BDF2HeartbeatScheduler"); mergedProps.setProperty("org.quartz.scheduler.instanceId", "HeartbeatDetectionScheduler"); mergedProps.setProperty("org.quartz.threadPool.threadCount","1"); factory.initialize(mergedProps); scheduler=factory.getScheduler(); }
private void initDetectionScheduler() throws Exception{ StdSchedulerFactory factory=new StdSchedulerFactory(); Properties mergedProps = new Properties(); mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); mergedProps.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", "true"); mergedProps.setProperty("org.quartz.scheduler.instanceName", "UfloClusterHeartbeatScheduler"); mergedProps.setProperty("org.quartz.scheduler.instanceId", "UfloHeartbeatDetectionScheduler"); mergedProps.setProperty("org.quartz.threadPool.threadCount","2"); factory.initialize(mergedProps); scheduler=factory.getScheduler(); }
public Scheduler createQuartzScheduler() throws SchedulerException { 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", "1"); properties.setProperty("org.quartz.jobStore.class", RAMJobStore.class.getName()); val schedulerFactory = new StdSchedulerFactory(properties); return schedulerFactory.getScheduler(); }
@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; }
/** * Load and/or apply Quartz properties to the given SchedulerFactory. * @param schedulerFactory the SchedulerFactory to initialize */ private void initSchedulerFactory(SchedulerFactory schedulerFactory) throws SchedulerException, IOException { if (!(schedulerFactory instanceof StdSchedulerFactory)) { if (this.configLocation != null || this.quartzProperties != null || this.taskExecutor != null || this.dataSource != null) { throw new IllegalArgumentException( "StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory); } // Otherwise assume that no initialization is necessary... return; } Properties mergedProps = new Properties(); if (this.resourceLoader != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, ResourceLoaderClassLoadHelper.class.getName()); } if (this.taskExecutor != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, LocalTaskExecutorThreadPool.class.getName()); } else { // Set necessary default properties here, as Quartz will not apply // its default configuration when explicitly given properties. mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT)); } if (this.configLocation != null) { if (logger.isInfoEnabled()) { logger.info("Loading Quartz config from [" + this.configLocation + "]"); } PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation); } CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps); if (this.dataSource != null) { mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName()); } // Make sure to set the scheduler name as configured in the Spring configuration. if (this.schedulerName != null) { mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName); } ((StdSchedulerFactory) schedulerFactory).initialize(mergedProps); }