當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。