本文整理汇总了Java中org.quartz.impl.StdSchedulerFactory.getDefaultScheduler方法的典型用法代码示例。如果您正苦于以下问题:Java StdSchedulerFactory.getDefaultScheduler方法的具体用法?Java StdSchedulerFactory.getDefaultScheduler怎么用?Java StdSchedulerFactory.getDefaultScheduler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.impl.StdSchedulerFactory
的用法示例。
在下文中一共展示了StdSchedulerFactory.getDefaultScheduler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleJob
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/**
* 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;
}
示例2: cancelAllJobs
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/**
* 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());
}
}
示例3: testCodedCronTriggerBean
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/**
* 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);
}
示例4: startHealthCheckJob
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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);
}
}
示例5: run
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
@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();
}
}
示例6: main
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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);
}
}
示例7: testQuartzAPI
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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("----------------------");
}
}
}
示例8: start
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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();
}
}
示例9: start
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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);
}
}
示例10: addGlobalJobListener
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
@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);
}
}
}
示例11: testToString
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/** 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());
}
示例12: scheduleJob
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/**
* 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());
}
}
示例13: scheduleRefreshJob
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
/**
* 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());
}
}
示例14: scheduleReconnect
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
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);
}
}
示例15: MetricsService
import org.quartz.impl.StdSchedulerFactory; //导入方法依赖的package包/类
public MetricsService() throws SchedulerException {
// I originally had this in start() but it looks like start() and
// the various ADD operations that are invoked after the subsystem
// is parsed can run in separate threads, so I had a race condition
// where something like createJob() would run before start(), resulting
// in an NPE because the scheduler was null. Not sure of the best way
// to do this...
log.debug("Creating metrics scheduler");
scheduler = StdSchedulerFactory.getDefaultScheduler();
// Is this the most appropriate executor type?
managementOperationExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable run) {
Thread thread = new Thread(run);
thread.setName("Metrics Management Client Thread");
thread.setDaemon(true);
return thread;
}
});
}