当前位置: 首页>>代码示例>>Java>>正文


Java Scheduler类代码示例

本文整理汇总了Java中org.quartz.Scheduler的典型用法代码示例。如果您正苦于以下问题:Java Scheduler类的具体用法?Java Scheduler怎么用?Java Scheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Scheduler类属于org.quartz包,在下文中一共展示了Scheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRunningJob

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * 所有正在运行的job
 * 
 * @return
 * @throws SchedulerException
 */
public List<ScheduleJob> getRunningJob() throws SchedulerException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
    List<ScheduleJob> jobList = new ArrayList<ScheduleJob>(executingJobs.size());
    for (JobExecutionContext executingJob : executingJobs) {
        ScheduleJob job = new ScheduleJob();
        JobDetail jobDetail = executingJob.getJobDetail();
        JobKey jobKey = jobDetail.getKey();
        Trigger trigger = executingJob.getTrigger();
        job.setName(jobKey.getName());
        job.setGroup(jobKey.getGroup());
        job.setDescription("触发器:" + trigger.getKey());
        Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
        job.setStatus(triggerState.name());
        if (trigger instanceof CronTrigger) {
            CronTrigger cronTrigger = (CronTrigger) trigger;
            String cronExpression = cronTrigger.getCronExpression();
            job.setCron(cronExpression);
        }
        jobList.add(job);
    }
    return jobList;
}
 
开发者ID:Zigin,项目名称:MonitorPlatform,代码行数:30,代码来源:JobConfigService.java

示例2: getAllJob

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * 获取所有计划中的任务列表
 * 
 * @return
 * @throws SchedulerException
 */
public List<ScheduleJob> getAllJob() throws SchedulerException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
    Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
    List<ScheduleJob> jobList = new ArrayList<ScheduleJob>();
    for (JobKey jobKey : jobKeys) {
        List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
        for (Trigger trigger : triggers) {
            ScheduleJob job = new ScheduleJob();
            job.setName(jobKey.getName());
            job.setGroup(jobKey.getGroup());
            job.setDescription("触发器:" + trigger.getKey());
            Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
            job.setStatus(triggerState.name());
            if (trigger instanceof CronTrigger) {
                CronTrigger cronTrigger = (CronTrigger) trigger;
                String cronExpression = cronTrigger.getCronExpression();
                job.setCron(cronExpression);
            }
            jobList.add(job);
        }
    }
    return jobList;
}
 
开发者ID:Zigin,项目名称:MonitorPlatform,代码行数:31,代码来源:JobConfigService.java

示例3: removeJob

import org.quartz.Scheduler; //导入依赖的package包/类
/** 
 * @Description 移除一个任务(使用默认的任务组名,触发器名,触发器组名) 
 * @param jobName 
 *  
 *  
 */  
public static void removeJob(String jobName) {   
    TriggerKey triggerKey = TriggerKey.triggerKey(  
            jobName, TRIGGER_GROUP_NAME);  
    JobKey jobKey = JobKey.jobKey(jobName, JOB_GROUP_NAME);  
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();  
        Trigger trigger = (Trigger) sched.getTrigger(triggerKey);    
        if (trigger == null) {    
            return;    
        }  
        sched.pauseTrigger(triggerKey);;// 停止触发器    
        sched.unscheduleJob(triggerKey);// 移除触发器    
        sched.deleteJob(jobKey);// 删除任务    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:24,代码来源:MicroQuartzManager.java

示例4: initialize

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * <p>
 * Called during creation of the <code>Scheduler</code> in order to give
 * the <code>SchedulerPlugin</code> a chance to initialize.
 * </p>
 * 
 * @throws SchedulerConfigException
 *           if there is an error initializing.
 */
public void initialize(String name, final Scheduler scheduler, ClassLoadHelper classLoadHelper)
    throws SchedulerException {

    getLog().info("Registering Quartz shutdown hook.");

    Thread t = new Thread("Quartz Shutdown-Hook "
            + scheduler.getSchedulerName()) {
        @Override
        public void run() {
            getLog().info("Shutting down Quartz...");
            try {
                scheduler.shutdown(isCleanShutdown());
            } catch (SchedulerException e) {
                getLog().info(
                        "Error shutting down Quartz: " + e.getMessage(), e);
            }
        }
    };

    Runtime.getRuntime().addShutdownHook(t);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ShutdownHookPlugin.java

示例5: wrapScheduleJob

import org.quartz.Scheduler; //导入依赖的package包/类
private void wrapScheduleJob(ScheduleJob scheduleJob,Scheduler scheduler,JobKey jobKey,Trigger trigger){  
    try {  
        scheduleJob.setJobName(jobKey.getName());  
        scheduleJob.setJobGroup(jobKey.getGroup()); 
  
        JobDetail jobDetail = scheduler.getJobDetail(jobKey);  
        ScheduleJob job = (ScheduleJob)jobDetail.getJobDataMap().get("scheduleJob");  
        scheduleJob.setDesc(job.getDesc());  
        scheduleJob.setJobId(job.getJobId());
  
        Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());  
        scheduleJob.setJobStatus(triggerState.name());  
        if(trigger instanceof CronTrigger){  
            CronTrigger cronTrigger = (CronTrigger)trigger;  
            String cronExpression = cronTrigger.getCronExpression();  
            scheduleJob.setCronExpression(cronExpression);  
        }  
    } catch (SchedulerException e) {  
        e.printStackTrace(); 
    }  
}
 
开发者ID:jiwenxing,项目名称:springboot-quartz,代码行数:22,代码来源:ScheduleJobService.java

示例6: stopService

import org.quartz.Scheduler; //导入依赖的package包/类
@Override
public void stopService() throws Exception {
    log.info("Stop QuartzService(" + jndiName + ")...");

    try {
        Scheduler scheduler = schedulerFactory.getScheduler();

        scheduler.shutdown();
    } catch (Exception e) {
        log.error("Failed to shutdown Scheduler", e);

        throw new SchedulerConfigException(
                "Failed to shutdown Scheduler - ", e);
    }

    unbind(jndiName);

    log.info("QuartzService(" + jndiName + ") stopped.");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:QuartzService.java

示例7: triggerJob

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * <p>
 * Store and schedule the identified <code>{@link org.quartz.spi.OperableTrigger}</code>
 * </p>
 */
public void triggerJob(OperableTrigger trig) throws SchedulerException {
    validateState();

    trig.computeFirstFireTime(null);

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:QuartzScheduler.java

示例8: execute

import org.quartz.Scheduler; //导入依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
	DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
	try {
		ISchedulerService service=jobDetail.getSchedulerService();
		if(!service.isRunJobInCurrentInstance()){
			log.warn("Current instance not allowed run scheduler!");
			return;
		}
		Scheduler scheduler=service.getCurrentScheduler();
		if(scheduler==null || scheduler.isShutdown()){
			System.out.println("Current instance scheduler was shutdown,start reset...");
			service.resetScheduer();
			System.out.println("Reset successful...");
		}
	} catch (Exception e) {
		throw new JobExecutionException(e);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:19,代码来源:DaemonDetectionJob.java

示例9: deleteScheduleJob

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * 删除定时任务
 */
public static void deleteScheduleJob(Scheduler scheduler, Long jobId) {
    try {
        scheduler.deleteJob(getJobKey(jobId));
    } catch (SchedulerException e) {
        throw new RRException("删除定时任务失败", e);
    }
}
 
开发者ID:gyp220203,项目名称:renren-msg,代码行数:11,代码来源:ScheduleUtils.java

示例10: wrapScheduleJob

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * 封装ScheduleJob对象
 * 
 * @param scheduleJob
 * @param scheduler
 * @param jobKey
 * @param trigger
 */
private void wrapScheduleJob(ScheduleJobEntity scheduleJob,
		Scheduler scheduler, JobKey jobKey, Trigger trigger) {
	try {
		scheduleJob.setJobName(jobKey.getName());
		scheduleJob.setJobGroup(jobKey.getGroup());

		JobDetail jobDetail = scheduler.getJobDetail(jobKey);
		scheduleJob.setJobClass(jobDetail.getJobClass());
		scheduleJob.setJobDesc(jobDetail.getDescription());
		
		Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
		scheduleJob.setTriggerStatus(triggerState.name());
		
		if (trigger instanceof CronTrigger) {
			CronTrigger cronTrigger = (CronTrigger) trigger;
			TriggerKey triggerKey = cronTrigger.getKey();
			scheduleJob.setTriggerName(triggerKey.getName());
			scheduleJob.setTriggerGroup(triggerKey.getGroup());
			scheduleJob.setNextFireTime(cronTrigger.getNextFireTime());
			scheduleJob.setCronExpression(cronTrigger.getCronExpression());
			scheduleJob.setStartDate(cronTrigger.getStartTime());
			scheduleJob.setEndDate(cronTrigger.getEndTime());
		}
	} catch (SchedulerException e) {
		logger.error("获取触发器状态失败", e);
		throw new ServiceException(e);
	}
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:37,代码来源:ScheduleJobServiceImpl.java

示例11: initialize

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * <p>
 * Called during creation of the <code>Scheduler</code> in order to give
 * the <code>SchedulerPlugin</code> a chance to initialize.
 * </p>
 * 
 * @throws SchedulerConfigException
 *           if there is an error initializing.
 */
public void initialize(String name, final Scheduler scheduler)
    throws SchedulerException {
    this.name = name;
    this.scheduler = scheduler;

    getLog().info("Registering Quartz shutdown hook.");

    Thread t = new Thread("Quartz Shutdown-Hook "
            + scheduler.getSchedulerName()) {
        public void run() {
            getLog().info("Shutting down Quartz...");
            try {
                scheduler.shutdown(isCleanShutdown());
            } catch (SchedulerException e) {
                getLog().info(
                        "Error shutting down Quartz: " + e.getMessage(), e);
            }
        }
    };

    Runtime.getRuntime().addShutdownHook(t);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:32,代码来源:ShutdownHookPlugin.java

示例12: triggerJobWithVolatileTrigger

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * <p>
 * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
 * now) - with a volatile trigger.
 * </p>
 */
public void triggerJobWithVolatileTrigger(SchedulingContext ctxt,
        String jobName, String groupName, JobDataMap data) throws SchedulerException {
    validateState();

    if(groupName == null) {
        groupName = Scheduler.DEFAULT_GROUP;
    }
    
    Trigger trig = new org.quartz.SimpleTrigger(newTriggerId(),
            Scheduler.DEFAULT_MANUAL_TRIGGERS, jobName, groupName,
            new Date(), null, 0, 0);
    trig.setVolatility(true);
    trig.computeFirstFireTime(null);
    if(data != null) {
        trig.setJobDataMap(data);
    }
    
    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(ctxt, trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setName(newTriggerId());
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:37,代码来源:QuartzScheduler.java

示例13: isJobWithNamePresent

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * Check job exist with given name
 */
@Override
public boolean isJobWithNamePresent(String jobName) {
	try {
		String groupKey = "SampleGroup";
		JobKey jobKey = new JobKey(jobName, groupKey);
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		if (scheduler.checkExists(jobKey)){
			return true;
		}
	} catch (SchedulerException e) {
		System.out.println("SchedulerException while checking job with name and group exist:"+e.getMessage());
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:javabypatel,项目名称:spring-boot-quartz-demo,代码行数:19,代码来源:JobServiceImpl.java

示例14: processStreamAndScheduleJobs

import org.quartz.Scheduler; //导入依赖的package包/类
/**
 * Process the xmlfile named <code>fileName</code> with the given system
 * ID.
 * 
 * @param stream
 *          an input stream containing the xml content.
 * @param systemId
 *          system ID.
 */
public void processStreamAndScheduleJobs(InputStream stream, String systemId, Scheduler sched)
    throws ValidationException, ParserConfigurationException,
        SAXException, XPathException, IOException, SchedulerException,
        ClassNotFoundException, ParseException {

    prepForProcessing();

    log.info("Parsing XML from stream with systemId: " + systemId);

    InputSource is = new InputSource(stream);
    is.setSystemId(systemId);

    process(is);
    executePreProcessCommands(sched);
    scheduleJobs(sched);

    maybeThrowValidationException();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:28,代码来源:XMLSchedulingDataProcessor.java

示例15: setUp

import org.quartz.Scheduler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    context = new ClassPathXmlApplicationContext(
    "core-context.xml",
    "applicationContext.xml");

    this.scheduler = (Scheduler) context.getBean("autowiringSchedulerFactoryBean");
    this.scheduler.start();

}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:AutowiringSchedulerFactoryBeanTests.java


注:本文中的org.quartz.Scheduler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。