/** * 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; }
/** * Refresh metadata. Schedules the job to retrieve metadata. * @throws SchedulerException the scheduler exception */ @PostConstruct public void refreshMetadata() throws SchedulerException { final Thread thread = new Thread(new Runnable() { @Override public void run() { buildMetadataResolverAggregate(); } }); thread.start(); final JobDetail job = JobBuilder.newJob(this.getClass()) .withIdentity(this.getClass().getSimpleName()).build(); final Trigger trigger = TriggerBuilder.newTrigger() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInMinutes(this.refreshIntervalInMinutes) .repeatForever()).build(); final SchedulerFactory schFactory = new StdSchedulerFactory(); final Scheduler sch = schFactory.getScheduler(); sch.start(); sch.scheduleJob(job, trigger); }
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(DataTask.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; } } }
/** * Delete all quartz scheduler jobs of the group <code>Dropbox</code>. */ private void cancelAllJobs() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); Set<JobKey> jobKeys = sched .getJobKeys(jobGroupEquals(SCHEDULER_GROUP)); if (jobKeys.size() > 0) { sched.deleteJobs(new ArrayList<JobKey>(jobKeys)); logger.debug( "Found {} MapDB-Jobs to delete from DefaulScheduler (keys={})", jobKeys.size(), jobKeys); } } catch (SchedulerException e) { logger.warn("Couldn't remove Commit-Job: {}", e.getMessage()); } }
/** * Ensures that jobs that are coded without a delay run without delay. * @throws Exception */ @Test public void testCodedCronTriggerBean() throws Exception { final String JOB_NAME = "codedCronJob"; List<Long> jobRuns = this.getRunList(JOB_NAME); assertEquals(0, jobRuns.size()); scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); CronTriggerBean ctBean = new CronTriggerBean(); ctBean.setBeanName("Dummy"); ctBean.setCronExpression("0/1 * * * * ? *"); ctBean.setEnabled(true); JobDetail jobDetail = new JobDetail(JOB_NAME, "DefaultGroup", DummyJob.class); ctBean.setJobDetail(jobDetail); ctBean.setScheduler(scheduler); ctBean.afterPropertiesSet(); assertJobRunsAfterInterval(jobRuns); scheduler.shutdown(); this.assertJobStopsAfterShutdown(jobRuns); }
public static void startHealthCheckJob() { try { // Grab the Scheduler instance from the Factory Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // and start it off scheduler.start(); // define the job and tie it to our Job class JobDetail job = newJob(DirectoryHealthCheck.class) .withIdentity("microserviceheartbeat", "heartbeats") .build(); // Trigger the job to run now, and then repeat every 90 seconds Trigger trigger = newTrigger() .withIdentity("microserviceHeartbeatTrigger", "DefaultTrigger") .startNow() .withSchedule(simpleSchedule() .withIntervalInSeconds(HEALTH_CHECK_FREQUENCY_SECONDS) .repeatForever()) .build(); // Tell quartz to schedule the job using our trigger scheduler.scheduleJob(job, trigger); } catch (SchedulerException ex) { Logger.getLogger(DirectoryHealthCheck.class.getName()).log(Level.SEVERE, null, ex); } }
/** * 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); } }
public DefaultTaskScheduler() { StdSchedulerFactory schedFactory = new StdSchedulerFactory(); Properties props = new Properties(); props.setProperty("org.quartz.scheduler.instanceName", "DefaultQuartzScheduler"); props.setProperty("org.quartz.scheduler.rmi.export", "false"); props.setProperty("org.quartz.scheduler.rmi.proxy", "false"); props.setProperty("org.quartz.scheduler.wrapJobExecutionInUserTransaction", "false"); props.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); props.setProperty("org.quartz.threadPool.threadCount", "10"); props.setProperty("org.quartz.jobStore.misfireThreshold", "60000"); props.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore"); try { schedFactory.initialize(props); quartz = schedFactory.getScheduler(); } catch (SchedulerException e) { throw new RuntimeException(e); } }
@Override public void run(String... strings) throws Exception { try { /* * 在 Quartz 中, scheduler 由 SchedulerFactory创建:DirectSchedulerFactory 或者 * StdSchedulerFactory。第二种工厂 StdSchedulerFactory 使用较多,因为 * DirectSchedulerFactory 使用起来不够方便,需要作许多详细的手工编码设置。 */ // 获取Scheduler实例 scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); // System.out.println("scheduler.start"); // System.out.println(scheduler.getSchedulerName()); // 注册任务 JobDetail jobDetail = JobBuilder.newJob(QuartzTask.class).withIdentity("QuartzTaskJob", "QuartzTaskGroup").build(); // 设置出发时间(每1天执行1次) SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(24).repeatForever(); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger", "group").startNow().withSchedule(simpleScheduleBuilder).build(); // 交由Scheduler安排触发 scheduler.scheduleJob(jobDetail, trigger); } catch (SchedulerException e) { e.printStackTrace(); } }
public serverTasks() throws SchedulerException, ParseException{ /* * 循环式的 */ SchedulerFactory factory = new StdSchedulerFactory(); Scheduler scheduler = factory.getScheduler(); //设置启动时间 DateBuilder.evenMinuteDate(new Date()); JobDetail job = JobBuilder.newJob(job.class).withIdentity("job1", "group1").build(); //job.getJobDataMap().put("a", true);//实现传参 // @NOTICE // 与SimpleTrigger对比:类不同了,现在的是Trigger的子类CronTrigger;withSchedule中的参数变为CronScheduleBuilder了 // CronScheduleBuilder可以通过类似"0/13 * * * * ?"这种表达式来创建定时任务 // 当前这个表达式的定义是30分钟执行一次 CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1") .withSchedule(CronScheduleBuilder.cronSchedule("1 0/30 * * * ?")).build(); scheduler.scheduleJob(job, trigger); scheduler.start(); //scheduler.shutdown(true); }
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; }
public static void main(String[] args) { try { final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); final JobDetail job = JobBuilder.newJob(MailFilterJob.class).build(); final Trigger trigger = TriggerBuilder.newTrigger() .startNow() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInMinutes(15) .repeatForever()) .build(); scheduler.scheduleJob(job, trigger); } catch (SchedulerException ex) { Logger.getLogger(MailFilterService.class.getName()).log(Level.SEVERE, null, ex); } }
@Bean(name = "batch") public SchedulerFactoryBean schedulerFactoryBean( DataSource dataSource, JobFactory jobFactory) { SchedulerFactoryBean factory = new SchedulerFactoryBean(); factory.setOverwriteExistingJobs(true); factory.setDataSource(dataSource); factory.setJobFactory(jobFactory); Properties props = new Properties(); props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "batch"); props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, "auto"); props.setProperty("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.HSQLDBDelegate"); props.setProperty("org.quartz.scheduler.skipUpdateCheck", "true"); // factory.setQuartzProperties(props); // factory.setTriggers(sampleJobTrigger); return factory; }
@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; }
@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; }
/** * Starts the main program and schedules the twitter post stats job * @param args (unused array of strings) */ public static void main(String[] args) throws IOException { logMsg("Twitter poster started...\n"); // Set the job logging level to "ERROR" and // schedule the station updater for every 60 seconds System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "ERROR"); JobDetail job = JobBuilder.newJob(TwitterPostStatsJob.class) .withIdentity("twitterPostStatsJob").build(); Trigger trigger = TriggerBuilder.newTrigger() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(60).repeatForever()).build(); // Schedule the twitter post stats job try { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); sched.start(); sched.scheduleJob(job, trigger); } catch (SchedulerException e) { logMsg("Error running the twitter post stats job..."); e.printStackTrace(); } }
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { try { _collector = collector; ru = new RedisUtil(); redis = ru.getJedisInstance(); SchedulerFactory schedulerFactory = new StdSchedulerFactory(); Scheduler scheduler = schedulerFactory.getScheduler(); _qManager = new QuartzManager(); _qManager.setScheduler(scheduler); PlatformUtils.initRegisterProject(_qManager); scheduler.start(); //init Hbase tables CreateTable.initHbaseTable(); }catch(Exception ex){ logger.error("error:"+MySysLogger.formatException(ex)); ex.printStackTrace(); } }
public void testQuartzAPI() throws SchedulerException, InterruptedException { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); for (int i = 1 ; i < 10; i++) { scheduler.scheduleJob(MockUtils.getEmptyJobDetail(String.valueOf(i)), MockUtils.getEmptyTrigger(String.valueOf(i))); } Thread.sleep(5000); for (;;) { List<JobExecutionContext> jobExecutionContexts = scheduler.getCurrentlyExecutingJobs(); for (JobExecutionContext jobExecutionContext : jobExecutionContexts) { System.out.println(JsonHelper.toJson(jobExecutionContext.getJobDetail().getKey().getGroup())); System.out.println(JsonHelper.toJson(jobExecutionContext.getJobDetail().getKey().getName())); System.out.println(JsonHelper.toJson(scheduler.getTriggerState(jobExecutionContext.getTrigger().getKey()))); System.out.println("----------------------"); } } }
public void start(final long interval) { try { // Grab the Scheduler instance from the Factory final org.quartz.Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // define the job and tie it to our NokiaHereAdapter class final JobDetail jd = new JobDetail(this.name, Scheduler.DEFAULT_GROUP, AdapterJob.class); // triggers all 120 seconds the execution of execution, never ends final SimpleTrigger simpleTrigger = new SimpleTrigger(this.name, Scheduler.DEFAULT_GROUP, new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, interval * 1000); // Tell quartz to schedule the job using our trigger scheduler.scheduleJob(jd, simpleTrigger); scheduler.start(); } catch (final SchedulerException se) { se.printStackTrace(); } }
@Test public void testQuartzComponentCustomScheduler() throws Exception { QuartzComponent comp = new QuartzComponent(); comp.setCamelContext(context); SchedulerFactory fac = new StdSchedulerFactory(); comp.setSchedulerFactory(fac); assertSame(fac, comp.getSchedulerFactory()); Scheduler sch = fac.getScheduler(); comp.setScheduler(sch); assertSame(sch, comp.getScheduler()); comp.start(); comp.stop(); }
@Test public void testQuartzComponentCustomScheduler() throws Exception { QuartzComponent comp = new QuartzComponent(); comp.setCamelContext(context); SchedulerFactory fac = new StdSchedulerFactory(); comp.setFactory(fac); assertSame(fac, comp.getFactory()); Scheduler sch = fac.getScheduler(); comp.setScheduler(sch); assertSame(sch, comp.getScheduler()); comp.start(); comp.stop(); }
@Override public boolean start() { try { // 加载配置文件 Properties props = PropKit.use(config).getProperties(); QuartzKit.INSTANTS.sf = new StdSchedulerFactory(props); // 获取Scheduler sched = QuartzKit.INSTANTS.sf.getScheduler(); QuartzKit.INSTANTS.scheduler = sched; log.info("QuartzKit.INSTANTS.scheduler:" + QuartzKit.INSTANTS.scheduler); // 启动 sched.start(); return true; } catch (Exception e) { Throwables.propagate(e); } return false; }
public SparkRedisStreaming() throws NumberFormatException, Exception{ // Quartz 1.6.3 JobDetail job = JobBuilder.newJob(SparkRedisStreaming.class).withIdentity("SparkRedisStreaming", "SparkRedisStreaming").build(); // Trigger the job to run on the next round minute Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("SparkRedisStreaming", "SparkRedisStreaming") .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(Integer.valueOf(getConfiguration().get("streaming.persistTime"))).repeatForever()).build(); // schedule it Scheduler scheduler = new StdSchedulerFactory().getScheduler(); scheduler.start(); scheduler.scheduleJob(job, trigger); }
public void init(int port){ log.info("init begin"); try { StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory(); stdSchedulerFactory.initialize("zeusQuartz.properties"); scheduler = stdSchedulerFactory.getScheduler(); scheduler.start(); } catch (SchedulerException e) { ScheduleInfoLog.error("schedule start fail", e); } dispatcher=new Dispatcher(); handler=new MasterHandler(this); server=new MasterServer(handler); server.start(port); master=new Master(this); log.info("init finish"); }
public JobScheduler(Properties properties) throws Exception { this.properties = properties; this.scheduler = new StdSchedulerFactory().getScheduler(); this.jobExecutor = Executors.newFixedThreadPool( Integer.parseInt(properties.getProperty(ConfigurationKeys.JOB_EXECUTOR_THREAD_POOL_SIZE_KEY, Integer.toString(ConfigurationKeys.DEFAULT_JOB_EXECUTOR_THREAD_POOL_SIZE))), ExecutorsUtils.newThreadFactory(Optional.of(LOG), Optional.of("JobScheduler-%d"))); this.jobConfigFileExtensions = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().split(this.properties .getProperty(ConfigurationKeys.JOB_CONFIG_FILE_EXTENSIONS_KEY, ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_EXTENSIONS))); long pollingInterval = Long.parseLong(this.properties.getProperty( ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, Long.toString(ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL))); this.fileAlterationMonitor = new FileAlterationMonitor(pollingInterval); }
/** * SimpleTrigger的使用 * * @throws org.quartz.SchedulerException */ public static void main(String[] args) throws SchedulerException { // 1、Grab the Scheduler instance from the Factory Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // 2、start scheduler.start(); // 3、 创建一个JobDetail实例 JobDetail job = JobBuilder.newJob(WakeMeUpJob.class).withIdentity("wakeMeUpJob", "group").build(); // 4、cron trigger,此处设置每天十点执行一次 CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 10 * * ?"); CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("wakeMeUpTrigger", "group").withSchedule(cronScheduleBuilder).build(); // 5、Tell quartz to schedule the job using our trigger scheduler.scheduleJob(job, trigger); // 6、shutdown // scheduler.shutdown(); }
/** * Utility method to schedule the job at a fixed interval. */ public static void schedule(MailSender mailSender, Configuration mailConfiguration, String group) throws SchedulerException { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = JobBuilder .newJob(MailSenderJob.class) .withIdentity("mail.sender", group) .build(); int pollInterval = mailConfiguration.getInt( MailProperties.MAIL_SENDER_POLL_INTERVAL, MailScheduler.DEFAULT_POLL_INTERVAL); Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("mail.sender.trigger", group) .startNow() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(pollInterval) .repeatForever()) .build(); scheduler.getContext().put(MailSenderJob.MAIL_SENDER_KEY, mailSender); scheduler.scheduleJob(job, trigger); }
@PostConstruct public void init() { try { // Load stored jobs. logger.debug("LOADING QUARTZ JOBS"); SchedulerFactory sf = new StdSchedulerFactory("quartz.properties"); scheduler = sf.getScheduler(); scheduler.start(); // classLoadHelper = new CascadingClassLoadHelper(); // classLoadHelper.initialize(); // processor = new XMLSchedulingDataProcessor(this.classLoadHelper); } catch (SchedulerException e) { e.printStackTrace(); // } catch (ParserConfigurationException e) { // e.printStackTrace(); } }
/** * Schedules new quartz scheduler job for uploading calendar entries to Google */ private void scheduleUploadJob() { try { Scheduler sched = 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(); sched.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()); } }
/** * 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()); } }
private void scheduleReconnect() { Scheduler sched; try { sched = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(ReconnectJob.class) .withIdentity("Reconnect", MPD_SCHEDULER_GROUP) .build(); CronTrigger trigger = newTrigger() .withIdentity("Reconnect", MPD_SCHEDULER_GROUP) .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?")) .build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled a daily MPD Reconnect of all MPDs"); } catch (SchedulerException se) { logger.warn("scheduling MPD Reconnect failed", se); } }
/** * Schedules a quartz job which is triggered every minute. */ public static void scheduleRefreshJob() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(RefreshJob.class) .withIdentity(REFRESH_JOB_KEY) .build(); SimpleTrigger trigger = newTrigger() .withIdentity(REFRESH_TRIGGER_KEY) .withSchedule(repeatSecondlyForever(refreshInterval)) .build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled refresh job '{}' in DefaulScheduler", job.getKey()); } catch (SchedulerException e) { logger.warn("Could not schedule refresh job: {}", e.getMessage()); } }
/** * Reschedules a quartz job which is triggered every minute. */ public static void rescheduleRefreshJob() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); SimpleTrigger trigger = newTrigger() .withIdentity(REFRESH_TRIGGER_KEY) .withSchedule(repeatSecondlyForever(refreshInterval)) .build(); sched.rescheduleJob(REFRESH_TRIGGER_KEY, trigger); logger.debug("Rescheduled refresh job '{}' in DefaulScheduler", REFRESH_TRIGGER_KEY); } catch (SchedulerException e) { logger.warn("Could not reschedule refresh job: {}", e.getMessage()); } }
/** * Schedules either a job handling the Upload (<code>LOCAL_TO_DROPBOX</code>) * or Download (<code>DROPBOX_TO_LOCAL</code>) direction depending on * <code>isUpload</code>. * * @param interval the Trigger interval as cron expression * @param isUpload */ private void schedule(String interval, boolean isUpload) { String direction = isUpload ? "Upload" : "Download"; try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(SynchronizationJob.class) .withIdentity(direction, DROPBOX_SCHEDULER_GROUP) .build(); CronTrigger trigger = newTrigger() .withIdentity(direction, DROPBOX_SCHEDULER_GROUP) .withSchedule(CronScheduleBuilder.cronSchedule(interval)) .build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled synchronization job (direction={}) with cron expression '{}'", direction, interval); } catch (SchedulerException e) { logger.warn("Could not create synchronization job: {}", e.getMessage()); } }
/** * 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); } }
@Override public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException { final Scheduler defaultScheduler; final List<Matcher<JobKey>> allJobs = new ArrayList<Matcher<JobKey>>(); allJobs.add(EverythingMatcher.allJobs()); if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) { defaultScheduler = null; LOG.debug("Initialization of Quartz default listener has been disabled"); } else { defaultScheduler = StdSchedulerFactory.getDefaultScheduler(); defaultScheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs); } for (final Scheduler scheduler : JobInformations.getAllSchedulers()) { if (scheduler != defaultScheduler) { scheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs); } } }
/** Test. * @throws SchedulerException e */ @Test public void testToString() throws SchedulerException { final Collector collector = createCollectorWithOneCounter(); assertToStringNotEmpty("collector", collector); assertToStringNotEmpty("java", new JavaInformations(null, false)); assertToStringNotEmpty("thread", new ThreadInformations(Thread.currentThread(), Arrays.asList(Thread.currentThread().getStackTrace()), 100, 1000, false, Parameters.getHostAddress())); assertToStringNotEmpty("session", new SessionInformations(new SessionTestImpl(true), true)); assertToStringNotEmpty("memory", new MemoryInformations()); CacheManager.getInstance().addCache("testToString"); try { assertToStringNotEmpty("cache", new CacheInformations( CacheManager.getInstance().getEhcache("testToString"), false)); } finally { CacheManager.getInstance().shutdown(); } final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); final JobDetail job = new JobDetail("job", null, JobTestImpl.class); assertToStringNotEmpty("job", new JobInformations(job, null, scheduler)); assertToStringNotEmpty("connectionInfos", new ConnectionInformations()); }
/** * Init servlet */ public void init(ServletConfig config) throws ServletException { super.init(config); try { schedFact = new StdSchedulerFactory("soa_quartz.properties"); sched = schedFact.getScheduler(); System.out.println(this.getClass().getName() + " started"); sched.start(); // Create Master Dispatch job JobDetail jd = new JobDetail(MASTER_JOB_NAME, GROUP_NAME, MasterSOAJob.class); int repeatInterval = Integer.parseInt(getInitParameter("TRIGGER_REPEATINTERVAL")); System.out.println(this.getClass().getName() + " Repeat interval for " + MASTER_JOB_NAME + ": " + repeatInterval + " milliseconds"); SimpleTrigger simpleTrigger = new SimpleTrigger(MASTER_TRIGGER_NAME, GROUP_NAME, SimpleTrigger.REPEAT_INDEFINITELY, repeatInterval); System.out.println(this.getClass().getName() + " Scheduling Job " + MASTER_JOB_NAME); sched.scheduleJob(jd, simpleTrigger); System.out.println(this.getClass().getName() + " Job " + MASTER_JOB_NAME + " scheduled"); } catch (Exception e) { System.err.println(this.getClass().getName() + " " + e.getLocalizedMessage()); e.printStackTrace(System.err); } }
public void start() { final JobDetail job = newJob(CrawlJob.class).withIdentity("CraigJob", "Crawl").build(); final Trigger trigger = newTrigger() .withIdentity(new TriggerKey("CraigTrigger", "Crawl")) .withSchedule( simpleSchedule().withIntervalInMinutes(60) .repeatForever()).startNow().build(); try { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.scheduleJob(job, trigger); scheduler.start(); } catch (SchedulerException e) { LOGGER.error("Error while scheduling job", e); } }