org.quartz.impl.StdSchedulerFactory Java Examples
The following examples show how to use
org.quartz.impl.StdSchedulerFactory.
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: CronModule.java From attic-aurora with Apache License 2.0 | 6 votes |
@Provides @Singleton 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", String.valueOf(options.cronSchedulerNumThreads)); 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; }
Example #2
Source File: QuartzInitializer.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
@Override public void init(SourceBean config) { StdSchedulerFactory stdSchedFact = new StdSchedulerFactory(); Properties properties = new Properties(); try { Thread currThread = Thread.currentThread(); ClassLoader classLoader = currThread.getContextClassLoader(); InputStream propIs = classLoader.getResourceAsStream("quartz.properties"); properties.load(propIs); String figuredOutValue = null; if (properties.containsKey(PROPERTY_DELEGATE_CLASS)) { logger.info("Quartz delegate class set to " + properties.get(PROPERTY_DELEGATE_CLASS)); } else { logger.warn("Property " + PROPERTY_DELEGATE_CLASS + " not set! Trying to figure out what delegate class needs to be used..."); determineDelegateClass(properties); } stdSchedFact.initialize(properties); Scheduler sched = stdSchedFact.getScheduler(); sched.start(); } catch (Exception e) { SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "init", "Error while initializing scheduler " + e); } }
Example #3
Source File: FHTBinding.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * The user may configure this binding to update the internal clock of * FHT80b devices via rf command. The method takes care of scheduling this * job. */ private JobKey scheduleJob(Class<? extends Job> jobClass, String cronExpression) { JobKey jobKey = null; try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobDetail detail = JobBuilder.newJob(jobClass).withIdentity("FHT " + jobClass.getSimpleName(), "cul") .build(); detail.getJobDataMap().put(FHTBinding.class.getName(), this); CronTrigger trigger = TriggerBuilder.newTrigger().forJob(detail) .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build(); jobKey = detail.getKey(); sched.scheduleJob(detail, trigger); } catch (SchedulerException e) { logger.error("Can't schedule time update job", e); } return jobKey; }
Example #4
Source File: CalDavLoaderImpl.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public void start() { super.start(); if (this.isProperlyConfigured()) { try { scheduler = new StdSchedulerFactory().getScheduler(); this.removeAllJobs(); } catch (SchedulerException e) { log.warn("Cannot get job scheduler", e); throw new IllegalStateException("Cannot get job scheduler", e); } this.startLoading(); } }
Example #5
Source File: QuartzPluginIT.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void executeApp() throws Exception { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); JobDetail job; Trigger trigger; try { job = createJob2x(); trigger = createTrigger2x(); } catch (ClassNotFoundException e) { job = createJob1x(); trigger = createTrigger1x(); } scheduler.scheduleJob(job, trigger); SECONDS.sleep(1); scheduler.shutdown(); }
Example #6
Source File: ScheduleAutoConfiguration.java From hsweb-framework with Apache License 2.0 | 6 votes |
@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 #7
Source File: SchedulerFactoryBean.java From java-technology-stack with MIT License | 6 votes |
/** * Create a SchedulerFactory if necessary and apply locally defined Quartz properties to it. * @return the initialized SchedulerFactory */ private SchedulerFactory prepareSchedulerFactory() throws SchedulerException, IOException { SchedulerFactory schedulerFactory = this.schedulerFactory; if (schedulerFactory == null) { // Create local SchedulerFactory instance (typically a StdSchedulerFactory) schedulerFactory = BeanUtils.instantiateClass(this.schedulerFactoryClass); if (schedulerFactory instanceof StdSchedulerFactory) { initSchedulerFactory((StdSchedulerFactory) schedulerFactory); } else if (this.configLocation != null || this.quartzProperties != null || this.taskExecutor != null || this.dataSource != null) { throw new IllegalArgumentException( "StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory); } // Otherwise, no local settings to be applied via StdSchedulerFactory.initialize(Properties) } // Otherwise, assume that externally provided factory has been initialized with appropriate settings return schedulerFactory; }
Example #8
Source File: MapDBPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Schedules new quartz scheduler jobs for committing transactions and * backing up the database */ private void scheduleJob() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); // schedule commit-job JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build(); SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP) .withSchedule(repeatSecondlyForever(commitInterval)).build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval); } catch (SchedulerException e) { logger.warn("Could not create Job: {}", e.getMessage()); } }
Example #9
Source File: DBSyncBuilder.java From mykit-db-sync with Apache License 2.0 | 6 votes |
/** * 启动定时任务,同步数据库的数据 */ public void start() { for (int index = 0; index < jobList.size(); index++) { JobInfo jobInfo = jobList.get(index); String logTitle = "[" + code + "]" + jobInfo.getName() + " "; try { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); JobDetail job = newJob(JobTask.class).withIdentity(MykitDbSyncConstants.JOB_PREFIX.concat(jobInfo.getName()), code).build(); job.getJobDataMap().put(MykitDbSyncConstants.SRC_DB, srcDb); job.getJobDataMap().put(MykitDbSyncConstants.DEST_DB, destDb); job.getJobDataMap().put(MykitDbSyncConstants.JOB_INFO, jobInfo); job.getJobDataMap().put(MykitDbSyncConstants.LOG_TITLE, logTitle); logger.info(jobInfo.getCron()); CronTrigger trigger = newTrigger().withIdentity(MykitDbSyncConstants.TRIGGER_PREFIX.concat(jobInfo.getName()), code).withSchedule(cronSchedule(jobInfo.getCron())).build(); sched.scheduleJob(job, trigger); sched.start(); } catch (Exception e) { e.printStackTrace(); logger.error(logTitle + e.getMessage()); logger.error(logTitle + " run failed"); continue; } } }
Example #10
Source File: DBSyncBuilder.java From mykit-db-sync with Apache License 2.0 | 6 votes |
/** * 启动定时任务,同步数据库的数据 */ public void start() { for (int index = 0; index < jobList.size(); index++) { JobInfo jobInfo = jobList.get(index); String logTitle = "[" + code + "]" + jobInfo.getName() + " "; try { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); JobDetail job = newJob(JobTask.class).withIdentity(MykitDbSyncConstants.JOB_PREFIX.concat(jobInfo.getName()), code).build(); job.getJobDataMap().put(MykitDbSyncConstants.SRC_DB, srcDb); job.getJobDataMap().put(MykitDbSyncConstants.DEST_DB, destDb); job.getJobDataMap().put(MykitDbSyncConstants.JOB_INFO, jobInfo); job.getJobDataMap().put(MykitDbSyncConstants.LOG_TITLE, logTitle); logger.info(jobInfo.getCron()); CronTrigger trigger = newTrigger().withIdentity(MykitDbSyncConstants.TRIGGER_PREFIX.concat(jobInfo.getName()), code).withSchedule(cronSchedule(jobInfo.getCron())).build(); sched.scheduleJob(job, trigger); sched.start(); } catch (Exception e) { e.printStackTrace(); logger.error(logTitle + e.getMessage()); logger.error(logTitle + " run failed"); continue; } } }
Example #11
Source File: TaskSchedulePlugin.java From dapeng-soa with Apache License 2.0 | 6 votes |
public TaskSchedulePlugin(Container container) { this.container = container; container.registerAppListener(this); if (scheduler == null) { try { scheduler = StdSchedulerFactory.getDefaultScheduler(); //添加监听器 scheduler.getListenerManager().addJobListener(new SchedulerJobListener()); scheduler.getListenerManager().addTriggerListener(new SchedulerTriggerListener()); } catch (SchedulerException e) { LOGGER.error("TaskSchedulePlugin 初始化出错", e); } } }
Example #12
Source File: MainClass.java From wechatGroupRobot with GNU General Public License v3.0 | 6 votes |
private static void cronTrigger() { JobDetail job = JobBuilder.newJob(WechatRobotJob.class).withIdentity("job1", "group1").build(); CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 6 ? * *"); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").withSchedule(cronScheduleBuilder).build(); JobDetail job2 = JobBuilder.newJob(WechatRobotJob2.class).withIdentity("job2", "group2").build(); CronScheduleBuilder cronScheduleBuilder2 = CronScheduleBuilder.cronSchedule("0 10 10,15,18,21 * * ?"); Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("trigger2", "group2").withSchedule(cronScheduleBuilder2).build(); SchedulerFactory schedulerFactory = new StdSchedulerFactory(); Scheduler scheduler = null; try { scheduler = schedulerFactory.getScheduler(); scheduler.scheduleJob(job, trigger); scheduler.scheduleJob(job2, trigger2); scheduler.start(); } catch (SchedulerException e) { e.printStackTrace(); } }
Example #13
Source File: DBSyncBuilder.java From Mykit with Apache License 2.0 | 6 votes |
/** * 启动定时任务,同步数据库的数据 */ public void start() { for (int index = 0; index < jobList.size(); index++) { JobInfo jobInfo = jobList.get(index); String logTitle = "[" + code + "]" + jobInfo.getName() + " "; try { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); JobDetail job = newJob(JobTask.class).withIdentity("job-" + jobInfo.getName(), code).build(); job.getJobDataMap().put("srcDb", srcDb); job.getJobDataMap().put("destDb", destDb); job.getJobDataMap().put("jobInfo", jobInfo); job.getJobDataMap().put("logTitle", logTitle); logger.info(jobInfo.getCron()); CronTrigger trigger = newTrigger().withIdentity("trigger-" + jobInfo.getName(), code).withSchedule(cronSchedule(jobInfo.getCron())).build(); sched.scheduleJob(job, trigger); sched.start(); } catch (Exception e) { logger.info(logTitle + e.getMessage()); logger.info(logTitle + " run failed"); continue; } } }
Example #14
Source File: CronService.java From aion-germany with GNU General Public License v3.0 | 6 votes |
public synchronized void init(Class<? extends RunnableRunner> runnableRunner) { if (scheduler != null) { return; } if (runnableRunner == null) { throw new CronServiceException("RunnableRunner class must be defined"); } this.runnableRunner = runnableRunner; Properties properties = new Properties(); properties.setProperty("org.quartz.threadPool.threadCount", "1"); try { scheduler = new StdSchedulerFactory(properties).getScheduler(); scheduler.start(); } catch (SchedulerException e) { throw new CronServiceException("Failed to initialize CronService", e); } }
Example #15
Source File: ChronixRetentionHandler.java From chronix.server with Apache License 2.0 | 6 votes |
/** * This method sets up a scheduled deletion job. */ private void scheduledDeletion() { System.setProperty("org.quartz.threadPool.threadCount", "3"); SchedulerFactory sf = new StdSchedulerFactory(); try { scheduler = sf.getScheduler(); Trigger trigger = newTrigger() .withIdentity("Data_Retention_Trigger") .startNow() .withSchedule(dailyAtHourAndMinute(removeDailyAt, 0)) .build(); JobDetail deletionJob = newJob(RetentionJob.class) .withIdentity("Data_Retention_Job") .usingJobData(RetentionConstants.RETENTION_URL, retentionURL) .build(); scheduler.scheduleJob(deletionJob, trigger); scheduler.startDelayed(180); } catch (SchedulerException e) { LOGGER.warn("Got an scheduler exception.", e); } }
Example #16
Source File: GCalPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Schedules new quartz scheduler job for uploading calendar entries to Google */ private void scheduleUploadJob() { try { scheduler = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(SynchronizationJob.class).withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP) .build(); SimpleTrigger trigger = newTrigger().withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP) .withSchedule(repeatSecondlyForever(uploadInterval)).build(); scheduler.scheduleJob(job, trigger); logger.debug("Scheduled Google Calendar Upload-Job with interval '{}'", uploadInterval); } catch (SchedulerException e) { logger.warn("Could not create Google Calendar Upload-Job: {}", e.getMessage()); } }
Example #17
Source File: SchedulerService.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
public void start() { try { SchedulerFactory sf = new StdSchedulerFactory(); scheduler = sf.getScheduler(); scheduler.start(); for (Map.Entry<String, Task> entry : tasks.entrySet()) { Task task = entry.getValue(); JobDetail job = newJob(SchedulerJob.class) .withIdentity(task.id) .build(); CronTrigger trigger = newTrigger() .withIdentity(task.id) .withSchedule(cronSchedule(task.cron)) .build(); scheduler.scheduleJob(job, trigger); } } catch (SchedulerException e) { throw new ApplicationException(e); } }
Example #18
Source File: Scheduler.java From thoth with BSD 3-Clause Clear License | 6 votes |
public void init() throws SchedulerException { if (isEnabled){ // Only shrink if specified JobDetail workerJob = JobBuilder.newJob(ShrinkerJob.class) .withIdentity("shrinkingJob", "group1").build(); Trigger workerTrigger = TriggerBuilder .newTrigger() .withIdentity("shrinkingTrigger", "group1") .withSchedule( CronScheduleBuilder.cronSchedule(schedule)) // execute this every day at midnight .build(); //Schedule it org.quartz.Scheduler scheduler = new StdSchedulerFactory().getScheduler(); scheduler.start(); scheduler.getContext().put("period", shrinkPeriod); scheduler.getContext().put("thothIndexUrl", thothIndexURL); scheduler.getContext().put("threadPoolSize", threadPoolSize); scheduler.scheduleJob(workerJob, workerTrigger); } }
Example #19
Source File: HRCronTriggerRunner.java From NewsRecommendSystem with MIT License | 5 votes |
public void task(List<Long> users,String cronExpression) throws SchedulerException { // Initiate a Schedule Factory SchedulerFactory schedulerFactory = new StdSchedulerFactory(); // Retrieve a scheduler from schedule factory Scheduler scheduler = schedulerFactory.getScheduler(); // Initiate JobDetail with job name, job group, and executable job class JobDetailImpl jobDetailImpl = new JobDetailImpl(); jobDetailImpl.setJobClass(HRJob.class); jobDetailImpl.setKey(new JobKey("HRJob1")); jobDetailImpl.getJobDataMap().put("users",users); // Initiate CronTrigger with its name and group name CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); cronTriggerImpl.setName("HRCronTrigger1"); try { // setup CronExpression CronExpression cexp = new CronExpression(cronExpression); // Assign the CronExpression to CronTrigger cronTriggerImpl.setCronExpression(cexp); } catch (Exception e) { e.printStackTrace(); } // schedule a job with JobDetail and Trigger scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl); // start the scheduler scheduler.start(); }
Example #20
Source File: SchedulerMainService.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
/** * 스케줄러 초기화 * @throws Exception * @return void */ public void JobInit() throws Exception { try { if (scheduler != null && scheduler.isStarted()) return; schedulerFactory = new StdSchedulerFactory(); scheduler = schedulerFactory.getScheduler(); scheduler.start(); JobRegist(); } catch (Exception e) { throw e; } }
Example #21
Source File: QuarzSchedulerDAOImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public QuarzSchedulerDAOImpl() { logger.debug("IN"); try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (Throwable t) { throw new SpagoBIDAOException("Impossible to access to the default quartz scheduler", t); } finally { logger.debug("OUT"); } }
Example #22
Source File: QuartzBundle.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
/** * Initialize scheduler and start JobManager * * @param properties * @throws SchedulerException */ private void initializeScheduler(Properties properties) throws SchedulerException { SchedulerFactory factory = new StdSchedulerFactory(properties); Scheduler scheduler = factory.getScheduler(); scheduler.start(); JobManager.initialize(scheduler); }
Example #23
Source File: InstanceDetection.java From uflo with Apache License 2.0 | 5 votes |
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(); }
Example #24
Source File: MyStromEcoPowerBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override public void activate() { try { scheduler = StdSchedulerFactory.getDefaultScheduler(); super.activate(); } catch (SchedulerException se) { logger.error("initializing scheduler throws exception", se); } }
Example #25
Source File: QuartzAdapter.java From javamelody with Apache License 2.0 | 5 votes |
public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException { final Scheduler defaultScheduler; if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) { defaultScheduler = null; LOG.debug("Initialization of Quartz default listener has been disabled"); } else { defaultScheduler = StdSchedulerFactory.getDefaultScheduler(); defaultScheduler.addGlobalJobListener(jobGlobalListener); } for (final Scheduler scheduler : JobInformations.getAllSchedulers()) { if (scheduler != defaultScheduler) { scheduler.addGlobalJobListener(jobGlobalListener); } } }
Example #26
Source File: BaseIntegrationTest.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { port = getPort(); redisServer = RedisServer.builder() .port(port) .build(); redisServer.start(); jedisPool = new JedisPool(HOST, port); scheduler = new StdSchedulerFactory(schedulerConfig(HOST, port)).getScheduler(); scheduler.start(); }
Example #27
Source File: AbstractScheduleManager.java From niubi-job with Apache License 2.0 | 5 votes |
protected void initScheduler(Properties properties) { this.properties = properties; try { StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(); schedulerFactory.initialize(properties); scheduler = schedulerFactory.getScheduler(); scheduler.start(); } catch (SchedulerException e) { LoggerHelper.error("create scheduler failed.", e); throw new NiubiException(e); } }
Example #28
Source File: ScheduleService.java From elasticsearch-quartz with Apache License 2.0 | 5 votes |
@Inject public ScheduleService(final Settings settings) { super(settings); logger.info("Creating Scheduler..."); final SchedulerFactory sf = new StdSchedulerFactory(); try { scheduler = sf.getScheduler(); } catch (final SchedulerException e) { throw new QuartzSchedulerException("Failed to create Scheduler.", e); } }
Example #29
Source File: JobScheduler.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
public JobScheduler(BimServer bimServer) { try { Properties properties = new Properties(); String instanceName = "UniqueName" + Math.random(); properties.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); properties.setProperty("org.quartz.threadPool.threadCount", "1"); properties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instanceName); sf = new StdSchedulerFactory(properties); sched = sf.getScheduler(); sched.getContext().put("bimserver", bimServer); } catch (SchedulerException e) { LOGGER.error("", e); } }
Example #30
Source File: SchedulerManager.java From SO with BSD 2-Clause "Simplified" License | 5 votes |
@PostConstruct public void schedulerManagerInit() { //public SchedulerManager() { try{ scheduler = new StdSchedulerFactory().getScheduler(); }catch(SchedulerException e){ e.printStackTrace(); } if(thread == null){ thread = new Thread(this); } if(!thread.isAlive()){ thread.start(); } }