org.quartz.Scheduler Java Examples

The following examples show how to use org.quartz.Scheduler. 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: App.java    From database-sync with MIT License 6 votes vote down vote up
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;
        }
    }
}
 
Example #2
Source File: SchedulerTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * This method runs the current job only once, right now
 * @return int 0 if it's not running, 1 if it is, 2 if there is an error
 */
public int getSelectedJobRunning()
{
   Scheduler scheduler = schedulerManager.getScheduler();
   if (scheduler == null)
   {
     log.error("Scheduler is down!");
     return 2;
   }
   try
   {
      List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
      JobKey selected = selectedJobDetailWrapper.getJobDetail().getKey();

      for (JobExecutionContext jobExecutionContext : executingJobs) {
         if(selected.equals(jobExecutionContext.getJobDetail().getKey()) )
            return 1;
      }
      return 0;
   }
   catch (Exception e)
   {
     log.error("Failed to trigger job now", e);
     return 2;
   }
}
 
Example #3
Source File: ConfigScheduler.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
private synchronized void schedule()
{
    try
    {
        scheduler = schedulerFactory.getScheduler();

        JobDetail job = JobBuilder.newJob()
                .withIdentity(jobName)
                .ofType(ConfigSchedulerJob.class)
                .build();
        jobKey = job.getKey();
        job.getJobDataMap().put(CONFIG_SCHEDULER, this);
        CronExpression cronExpression = normalCronSchedule ? this.cronExpression : initialAndOnErrorCronExpression;
        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(jobName+"Trigger", Scheduler.DEFAULT_GROUP)
                .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
                .build();
        scheduler.startDelayed(0);
        scheduler.scheduleJob(job, trigger);
        log.debug("Schedule set "+cronExpression);
    }
    catch (Exception e)
    {
        log.error("Error scheduling "+e.getMessage());
    }
}
 
Example #4
Source File: QuartzService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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.");
}
 
Example #5
Source File: DBSyncBuilder.java    From mykit-db-sync with Apache License 2.0 6 votes vote down vote up
/**
 * 启动定时任务,同步数据库的数据
 */
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 #6
Source File: FHTBinding.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: SchedulerFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Expose the specified context attributes and/or the current
 * ApplicationContext in the Quartz SchedulerContext.
 */
private void populateSchedulerContext(Scheduler scheduler) throws SchedulerException {
	// Put specified objects into Scheduler context.
	if (this.schedulerContextMap != null) {
		scheduler.getContext().putAll(this.schedulerContextMap);
	}

	// Register ApplicationContext in Scheduler context.
	if (this.applicationContextSchedulerContextKey != null) {
		if (this.applicationContext == null) {
			throw new IllegalStateException(
				"SchedulerFactoryBean needs to be set up in an ApplicationContext " +
				"to be able to handle an 'applicationContextSchedulerContextKey'");
		}
		scheduler.getContext().put(this.applicationContextSchedulerContextKey, this.applicationContext);
	}
}
 
Example #8
Source File: StdSchedulerFactory.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Returns a handle to the Scheduler produced by this factory.
 * </p>
 *
 * <p>
 * If one of the <code>initialize</code> methods has not be previously
 * called, then the default (no-arg) <code>initialize()</code> method
 * will be called by this method.
 * </p>
 */
public Scheduler getScheduler() throws SchedulerException {
    if (cfg == null) {
        initialize();
    }

    SchedulerRepository schedRep = SchedulerRepository.getInstance();

    Scheduler sched = schedRep.lookup(getSchedulerName());

    if (sched != null) {
        if (sched.isShutdown()) {
            schedRep.remove(getSchedulerName());
        } else {
            return sched;
        }
    }

    sched = instantiate();

    return sched;
}
 
Example #9
Source File: QuartzJobHandler.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public static void listJobs(Scheduler scheduler) throws SchedulerException {
	if (!LOG.isDebugEnabled()) {
		return;
	}
	
	List<String> jobGroups = scheduler.getJobGroupNames();
	if (jobGroups.isEmpty()) {
		LOG.debug("No jobs !!!");
	}

	for (String jobGroup : jobGroups) {
		LOG.debug("Group '{}' contains the following jobs:", jobGroup);
		Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup));
		for (JobKey jobKey : jobKeys) {
			LOG.debug("- {}", jobKey.getName());
		}
	}
}
 
Example #10
Source File: BatchJobOperatorImpl.java    From griffin with Apache License 2.0 6 votes vote down vote up
@Override
public JobState getState(AbstractJob job, String action)
    throws SchedulerException {
    JobState jobState = new JobState();
    Scheduler scheduler = factory.getScheduler();
    if (job.getGroup() == null || job.getName() == null) {
        return null;
    }
    TriggerKey triggerKey = triggerKey(job.getName(), job.getGroup());
    TriggerState triggerState = scheduler.getTriggerState(triggerKey);
    jobState.setState(triggerState.toString());
    jobState.setToStart(getStartStatus(triggerState));
    jobState.setToStop(getStopStatus(triggerState));
    setTriggerTime(job, jobState);
    return jobState;
}
 
Example #11
Source File: Quartz2Adapter.java    From javamelody with Apache License 2.0 6 votes vote down vote up
@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);
		}
	}
}
 
Example #12
Source File: QuartzPluginIT.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: QuartzInitializer.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: QuartzManager.java    From quartz-web with Apache License 2.0 5 votes vote down vote up
/**
 * 更新Trigger
 * @param schedulerName
 * @param trigger
 * @throws SchedulerException
 */
public void updateTriggerForJob(String schedulerName, Trigger trigger) throws SchedulerException {
    Assert.notNull(trigger, "trigger can not be null");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    if (existTrigger(schedulerName, QuartzUtils.getTriggerName(trigger), QuartzUtils.getTriggerGroup(trigger))) {
        scheduler.rescheduleJob(trigger.getKey(), trigger);
    } else {
        throw new IllegalArgumentException("trigger [" + trigger.getKey().getName() +
                ":" + trigger.getKey().getGroup() + "] not exist");
    }
}
 
Example #15
Source File: QuartzUtil.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public static Map<String, JobExecutionContext> getRunningJobs(Scheduler scheduler) throws SchedulerException {
	Map<String, JobExecutionContext> runningJobs = new HashMap<String, JobExecutionContext>();
	List<JobExecutionContext> jobs = scheduler.getCurrentlyExecutingJobs();
	for (JobExecutionContext context : jobs) {
		runningJobs.put(context.getJobDetail().getKey().getName(), context);
	}
	
	return runningJobs;		
}
 
Example #16
Source File: ScheduleUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 获取表达式触发器
 */
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId)
{
    try
    {
        return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
    }
    catch (SchedulerException e)
    {
        log.error("getCronTrigger 异常:", e);
    }
    return null;
}
 
Example #17
Source File: BatchJobOperatorImpl.java    From griffin with Apache License 2.0 5 votes vote down vote up
public void deleteJob(String group, String name) throws SchedulerException {
    Scheduler scheduler = factory.getScheduler();
    JobKey jobKey = new JobKey(name, group);
    if (!scheduler.checkExists(jobKey)) {
        LOGGER.info("Job({},{}) does not exist.", jobKey.getGroup(), jobKey
            .getName());
        return;
    }
    scheduler.deleteJob(jobKey);

}
 
Example #18
Source File: SchedulerUtil.java    From SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 执行计划任务
 * @param job
 * @param trigger
 * @return
 * @throws SchedulerException
 */
public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException {
    ScheduleJobResult scheduleJobResult = new ScheduleJobResult();
    //判断是否满足计划任务的创建条件
    if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED);
        //不满足计划任务的创建条件,返回scheduleJobResult值类
        return scheduleJobResult;
    }
    scheduleJobResult.setJobDetail(job);
    scheduleJobResult.setTrigger(trigger);
    //开始分配计划任务
    Scheduler scheduler  = SchedulerFactory.getScheduler();
    //开始判断是否存在相同的计划任务
    if(scheduler.checkExists(job.getKey())){
        log.info("存在相同的计划任务:{}",job.getKey());
        scheduler.deleteJob(job.getKey());
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST);
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
    }else{
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS);
    }
    //计划任务分配成功
    return scheduleJobResult;
}
 
Example #19
Source File: CBCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
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(CBJob.class);
    jobDetailImpl.setKey(new JobKey("CBJob1"));
    jobDetailImpl.getJobDataMap().put("users", users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("CBCronTrigger1");
    
    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: QuartzManager.java    From quartz-web with Apache License 2.0 5 votes vote down vote up
/**
 * 延时启动
 * @param schedulerName
 * @param delayed 延迟秒数
 * @throws SchedulerException
 */
public void schedulerStart(String schedulerName, int delayed) throws SchedulerException {
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    if (!scheduler.isStarted()) {
        if (delayed <= 0) {
            scheduler.start();
        } else {
            scheduler.startDelayed(delayed);
        }
    }
}
 
Example #21
Source File: MessagingServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private void scheduleJob() {
    LOG.debug("Queueing processing job");
    try {
        Scheduler scheduler = KSBServiceLocator.getScheduler();
        if (synchronous) {
            LOG.debug("Invoking job synchronously in Thread " + Thread.currentThread());
            MessageProcessingJob job = new MessageProcessingJob(messageId, mode, user, cause);
            job.run();
        } else {
            String uniqueTriggerName = jobName + "-Trigger-" + System.currentTimeMillis() + Math.random();
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(uniqueTriggerName, jobGroup + "-Trigger");
            LOG.debug("Scheduling trigger: " + trigger);

            JobDataMap data = new JobDataMap();
            data.put("mode", mode.name());
            data.put("user", user);
            data.put("cause", cause);
            data.put("messageId", messageId);

            trigger.setJobName(jobName);
            trigger.setJobGroup(jobGroup);
            trigger.setJobDataMap(data);
            scheduler.scheduleJob(trigger);
        }
    } catch (SchedulerException se) {
        throw new RuntimeException(se);
    }
}
 
Example #22
Source File: SchedulerManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public Scheduler getScheduler(String schedName) throws SchedulerException
{
  if (scheduler.getSchedulerName().equals(schedName))
  {
    return getScheduler();
  }
  return null;
}
 
Example #23
Source File: JobNamerTest.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Test
public void getJobKey(@Mock Report report) {
    String uuid = UUID.randomUUID().toString();
    when(report.getKey()).thenReturn(uuid);
    assertTrue(EqualsBuilder.reflectionEquals(new JobKey("reportJob" + report.getKey(), Scheduler.DEFAULT_GROUP),
            JobNamer.getJobKey(report)));
}
 
Example #24
Source File: QuartzManager.java    From quartz-web with Apache License 2.0 5 votes vote down vote up
public Trigger getTrigger(String schedulerName,String triggerName,String triggerGroup) throws SchedulerException {
    Assert.notEmpty(triggerName, "triggerName can not be empty");
    Assert.notEmpty(triggerGroup, "triggerGroup can not be empty");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    TriggerKey triggerKey = QuartzUtils.getTriggerKey(triggerName, triggerGroup);
    Trigger trigger = scheduler.getTrigger(triggerKey);
    return trigger;
}
 
Example #25
Source File: DynamicJobFactory.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
    Map<String, Object> data = bundle.getJobDetail().getJobDataMap();
    String jobId = (String) data.get(JOB_ID_KEY);
    if (null == jobId || bundle.getJobDetail().getJobClass() != DynamicJob.class) {
        return defaultFactory.newJob(bundle, scheduler);
    }
    return  context -> scheduleJobExecutor.doExecuteJob(jobId, data);
}
 
Example #26
Source File: ScheduleUtils.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 删除定时任务
 */
public static void deleteScheduleJob(Scheduler scheduler, Long jobId)
{
    try
    {
        scheduler.deleteJob(getJobKey(jobId));
    }
    catch (SchedulerException e)
    {
        log.error("deleteScheduleJob 异常:", e);
    }
}
 
Example #27
Source File: ExportResource.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@POST
@Path("/cockpitData")
@Produces(MediaType.APPLICATION_JSON)
public Response exportCockpitDocumentWidgetData(DocumentExportConf documentExportConf) {
	logger.debug("IN");

	logger.debug(String.format("document id: %s", documentExportConf.getDocumentId()));
	logger.debug(String.format("document label: %s", documentExportConf.getDocumentLabel()));
	logger.debug(String.format("export type: %s", documentExportConf.getExportType()));
	logger.debug(String.format("parameters: %s", documentExportConf.getParameters()));

	JobDetail exportJob = new CockpitDataExportJobBuilder().setDocumentExportConf(documentExportConf).setLocale(request.getLocale())
			.setUserProfile(UserProfileManager.getProfile()).build();
	logger.debug("Created export job");

	try {
		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
		scheduler.addJob(exportJob, true);
		scheduler.triggerJob(exportJob.getName(), exportJob.getGroup());
		logger.debug("Export job triggered ");
	} catch (SchedulerException e) {
		String msg = String.format("Error during scheduling of export job for cokcpit document %d", documentExportConf.getDocumentLabel());
		logger.error(msg, e);
		throw new SpagoBIRuntimeException(msg);
	}
	logger.debug("OUT");
	return Response.ok().entity(exportJob.getName()).build();

}
 
Example #28
Source File: SchedulerAccessorBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Scheduler findDefaultScheduler() {
	if (this.beanFactory != null) {
		return this.beanFactory.getBean(Scheduler.class);
	}
	else {
		throw new IllegalStateException(
				"No Scheduler specified, and cannot find a default Scheduler without a BeanFactory");
	}
}
 
Example #29
Source File: JobServiceImpl.java    From spring-boot-quartz-demo with MIT License 5 votes vote down vote up
/**
 * Schedule a job by jobName at given date.
 */
@Override
public boolean scheduleOneTimeJob(String jobName, Class<? extends QuartzJobBean> jobClass, Date date) {
	System.out.println("Request received to scheduleJob");

	String jobKey = jobName;
	String groupKey = "SampleGroup";	
	String triggerKey = jobName;		

	JobDetail jobDetail = JobUtil.createJob(jobClass, false, context, jobKey, groupKey);

	System.out.println("creating trigger for key :"+jobKey + " at date :"+date);
	Trigger cronTriggerBean = JobUtil.createSingleTrigger(triggerKey, date, SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
	//Trigger cronTriggerBean = JobUtil.createSingleTrigger(triggerKey, date, SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);

	try {
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		Date dt = scheduler.scheduleJob(jobDetail, cronTriggerBean);
		System.out.println("Job with key jobKey :"+jobKey+ " and group :"+groupKey+ " scheduled successfully for date :"+dt);
		return true;
	} catch (SchedulerException e) {
		System.out.println("SchedulerException while scheduling job with key :"+jobKey + " message :"+e.getMessage());
		e.printStackTrace();
	}

	return false;
}
 
Example #30
Source File: StdSchedulerFactory.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
protected Scheduler instantiate(QuartzSchedulerResources rsrcs, QuartzScheduler qs) {
    SchedulingContext schedCtxt = new SchedulingContext();
    schedCtxt.setInstanceId(rsrcs.getInstanceId());

    Scheduler scheduler = new StdScheduler(qs, schedCtxt);
    return scheduler;
}