예제 #1
0
  public void quartzTest() throws Exception {

    JobDetail jobDetail =
        JobBuilder.newJob(QuartsDemo.class).withIdentity("testJob_1", "group_1").build();

    Trigger trigger =
        TriggerBuilder.newTrigger()
            .withIdentity("trigger_1", "group_1")
            .startNow()
            .withSchedule(
                SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInSeconds(1) // 时间间隔
                    .withRepeatCount(10) // 重复次数(将执行 10 次/ or //调用10次)
                )
            .build();
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    sched.scheduleJob(jobDetail, trigger);

    sched.start();

    Thread.currentThread().sleep(20000);

    System.err.println("关闭  ");
    sched.shutdown();
  }
  public void run() throws Exception {

    Log log = LogFactory.getLog(RemoteClientExample.class);

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    // define the job and ask it to run
    JobDetail job = new JobDetail("remotelyAddedJob", "default", SimpleJob.class);
    JobDataMap map = new JobDataMap();
    map.put("msg", "Your remotely added job has executed!");
    job.setJobDataMap(map);
    CronTrigger trigger =
        new CronTrigger(
            "remotelyAddedTrigger",
            "default",
            "remotelyAddedJob",
            "default",
            new Date(),
            null,
            "/5 * * ? * *");

    // schedule the job
    sched.scheduleJob(job, trigger);

    log.info("Remote job scheduled.");
  }
  protected Scheduler getSyncScheduler() {
    if (syncScheduler == null) {
      synchronized (lock) {
        if (syncScheduler == null) {
          Properties mergedProps = new Properties();
          mergedProps.setProperty(
              StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
          mergedProps.setProperty("org.quartz.threadPool.threadCount", "1");
          mergedProps.setProperty(
              StdSchedulerFactory.PROP_SCHED_SKIP_UPDATE_CHECK, "true"); // 跳过版本检查
          mergedProps.put(
              StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "QuartzTimetaskSynchronizer");
          SchedulerFactory schedulerFactory = new StdSchedulerFactory();

          try {
            ((StdSchedulerFactory) schedulerFactory).initialize(mergedProps);
            syncScheduler = schedulerFactory.getScheduler();
          } catch (SchedulerException e) {
            logger.error("Error when creating timetask synchronizer for " + this.getName(), e);
          }
        }
      }
    }
    return syncScheduler;
  }
예제 #4
0
  public void run() throws Exception {
    // 通过SchedulerFactory获取一个调度器实例
    SchedulerFactory sf = new StdSchedulerFactory();

    Scheduler sched = sf.getScheduler();

    Date runTime = evenMinuteDate(new Date());

    // 通过过JobDetail封装HelloJob,同时指定Job在Scheduler中所属组及名称,这里,组名为group1,而名称为job1。
    JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1").build();

    // 创建一个SimpleTrigger实例,指定该Trigger在Scheduler中所属组及名称。
    // 接着设置调度的时间规则.当前时间运行
    Trigger trigger = newTrigger().withIdentity("trigger1", "group1").startAt(runTime).build();

    // 注册并进行调度
    sched.scheduleJob(job, trigger);

    // 启动调度器
    sched.start();

    try {
      // 当前线程等待65秒
      Thread.sleep(65L * 1000L);
    } catch (Exception e) {

    }

    // 调度器停止运行
    sched.shutdown(true);

    log.error("结束运行。。。。");
  }
예제 #5
0
  private void scheduleCronJob(String cronString, String elementId) {
    try {
      SchedulerFactory schedulerFactory = new StdSchedulerFactory();
      scheduler = schedulerFactory.getScheduler();
      scheduler.start();

      JobDataMap dataMap = new JobDataMap();
      dataMap.put("trigger", this);

      jobName = "TriggerJob_" + elementId;
      JobDetail job =
          org.quartz.JobBuilder.newJob(CronEventTrigger.class)
              .withIdentity(jobName, jobGroup)
              .usingJobData(dataMap)
              .build();

      Trigger trigger =
          org.quartz.TriggerBuilder.newTrigger()
              .withIdentity("TriggerJob_" + elementId, jobGroup)
              .withSchedule(CronScheduleBuilder.cronSchedule(cronString))
              .build();

      scheduler.scheduleJob(job, trigger);

    } catch (SchedulerException e) {
      log.error(
          "Error while instantiating quartz scheduler for trigger '"
              + triggerDefinition.getId()
              + "',"
              + e.getMessage(),
          e);
    }
  }
  /**
   * This example will spawn a large number of jobs to run
   *
   * @author James House, Bill Kratzer
   */
  public void run() throws Exception {
    Logger log = LoggerFactory.getLogger(RemoteServerExample.class);

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    log.info("------- 初始化完成 -----------");

    log.info("------- (Not Scheduling any Jobs - relying on a remote client to schedule jobs --");

    log.info("------- 开始调度工作 ----------------");

    // start the schedule
    sched.start();

    log.info("------- 调度工作开始 -----------------");

    log.info("------- 等待 ten minutes... ------------");

    // wait five minutes to give our jobs a chance to run
    try {
      Thread.sleep(600L * 1000L);
    } catch (Exception e) {
    }

    // shut down the scheduler
    log.info("------- 关闭 ---------------------");
    sched.shutdown(true);
    log.info("------- 关闭完成 -----------------");

    SchedulerMetaData metaData = sched.getMetaData();
    log.info("执行" + metaData.getNumberOfJobsExecuted() + "工作。");
  }
  private void startScheduler() {
    SchedulerFactory sf = new StdSchedulerFactory();
    try {
      sched = sf.getScheduler();

      JobDetail notificationCleanupJob =
          newJob(NotificationCleanupJob.class)
              .withIdentity("notificationCleanupJob", "chatServer")
              .build();

      CronTrigger notificationTrigger =
          newTrigger()
              .withIdentity("notificationTrigger", "chatServer")
              .withSchedule(
                  cronSchedule(
                      PropertyManager.getProperty(PropertyManager.PROPERTY_CRON_NOTIF_CLEANUP)))
              .build();

      sched.scheduleJob(notificationCleanupJob, notificationTrigger);

      sched.start();

      log.info("Scheduler Started");

    } catch (SchedulerException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
예제 #8
0
  /**
   * This example will spawn a large number of jobs to run
   *
   * @author James House, Bill Kratzer
   */
  public void run() throws Exception {
    Logger log = LoggerFactory.getLogger(RemoteServerExample.class);

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    log.info("------- Initialization Complete -----------");

    log.info("------- (Not Scheduling any Jobs - relying on a remote client to schedule jobs --");

    log.info("------- Starting Scheduler ----------------");

    // start the schedule
    sched.start();

    log.info("------- Started Scheduler -----------------");

    log.info("------- Waiting ten minutes... ------------");

    // wait five minutes to give our jobs a chance to run
    try {
      Thread.sleep(600L * 1000L);
    } catch (Exception e) {
      //
    }

    // shut down the scheduler
    log.info("------- Shutting Down ---------------------");
    sched.shutdown(true);
    log.info("------- Shutdown Complete -----------------");

    SchedulerMetaData metaData = sched.getMetaData();
    log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs.");
  }
예제 #9
0
 JobScheduler() throws JobSchedulerException {
   org.quartz.spi.JobFactory jobFactory = new JobFactory();
   SchedulerFactory schedulerFactory = new StdSchedulerFactory();
   try {
     scheduler = schedulerFactory.getScheduler();
     scheduler.setJobFactory(jobFactory);
   } catch (SchedulerException e) {
     throw new JobSchedulerException("An exception occurred during scheduler setup", e);
   }
 }
예제 #10
0
  public void scheduleJobs() throws Exception {

    System.out.println("------- Initializing ----------------------");
    checkConfiguration();

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    sched = sf.getScheduler();
    sched.deleteJob(JobKey.jobKey("event-search-job", "search.broker.jobs"));
    sched.deleteJob(JobKey.jobKey("traffic-search-job", "search.broker.jobs"));
    // sched.deleteJob(JobKey.jobKey("sport-search-job",  "search.broker.jobs"));
    // sched.deleteJob(JobKey.jobKey("data-analysis-job", "search.broker.jobs"));

    System.out.println("------- Initialization Complete -----------");
    System.out.println("------- Scheduling Jobs -------------------");

    // Job #1 is scheduled to run every 3 minutes
    JobDetail evtJob =
        newJob(EventSearchJob.class).withIdentity("event-search-job", "search.broker.jobs").build();
    Trigger ET =
        newTrigger()
            .withIdentity("event-trigger", "search.broker.jobs")
            .startNow()
            .withSchedule(simpleSchedule().withIntervalInSeconds(60 * 03).repeatForever())
            .build();

    JobDetail tfcJob =
        newJob(TrafficSearchJob.class)
            .withIdentity("traffic-search-job", "search.broker.jobs")
            .build();
    Trigger TT =
        newTrigger()
            .withIdentity("traffic-trigger", "search.broker.jobs")
            .startNow()
            .withSchedule(simpleSchedule().withIntervalInSeconds(60 * 03).repeatForever())
            .build();

    /*JobDetail danJob = newJob(DataAnalysisJob.class).withIdentity("data-analysis-job", "search.broker.jobs").build();
    Trigger DT = newTrigger().withIdentity("analysis-trigger", "search.broker.jobs")
    				  .startNow().withSchedule(simpleSchedule().withIntervalInSeconds(60*15).repeatForever())
    		          .build();

       JobDetail spoJob = newJob(SportSearchJob.class).withIdentity("sport-search-job", "search.broker.jobs").build();
    Trigger ST = newTrigger().withIdentity("sport-trigger", "search.broker.jobs")
    				  .startNow().withSchedule(simpleSchedule().withIntervalInSeconds(60*10).repeatForever())
    		          .build();*/

    sched.scheduleJob(tfcJob, TT);
    sched.scheduleJob(evtJob, ET);
    // sched.scheduleJob(spoJob, ST);
    // sched.scheduleJob(danJob, DT);

    sched.start();
    System.out.println("[eduzi] all jobs started.");
  }
예제 #11
0
  public Registration run() throws Exception {

    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    final Scheduler scheduler = schedulerFactory.getScheduler();
    scheduler.setJobFactory(jobFactory.get());
    for (Job j : jobProvider.get()) {

      JobDetail jobDetail =
          JobBuilder.newJob(j.getClass())
              .withIdentity(j.getClass().getSimpleName() + "Job")
              .build();

      if (shouldInstall(j.getClass())) {
        ScheduleInterval interval = j.getClass().getAnnotation(ScheduleInterval.class);
        if (interval != null) {
          Trigger trigger =
              TriggerBuilder.newTrigger()
                  .withIdentity(j.getClass().getSimpleName() + "TriggerId")
                  .withSchedule(
                      SimpleScheduleBuilder.simpleSchedule()
                          .withIntervalInSeconds(interval.value())
                          .repeatForever())
                  .build();
          System.out.println(
              "Schedule " + j.getClass().getSimpleName() + " @ " + interval.value() + "sec");
          scheduler.scheduleJob(jobDetail, trigger);
        }

        CronInterval cron = j.getClass().getAnnotation(CronInterval.class);
        if (cron != null) {
          Trigger trigger =
              TriggerBuilder.newTrigger()
                  .withIdentity(j.getClass().getSimpleName() + "TriggerId")
                  .withSchedule(CronScheduleBuilder.cronSchedule(cron.value()))
                  .build();
          System.out.println("Schedule " + j.getClass().getSimpleName() + " @ " + cron.value());
          scheduler.scheduleJob(jobDetail, trigger);
        }
      }
    }

    scheduler.start();
    return new Registration() {
      public void unregister() {
        try {
          scheduler.shutdown();
        } catch (Exception e) {
        }
        System.out.println("Schedular Stopped");
      }
    };
  }
예제 #12
0
  public void run() throws Exception {
    Logger log = LoggerFactory.getLogger(SimpleExample.class);

    log.info("------- Initializing ----------------------");

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    log.info("------- Initialization Complete -----------");

    // computer a time that is on the next round minute
    Date runTime = evenMinuteDate(new Date());

    log.info("------- Scheduling Job  -------------------");

    // define the job and tie it to our HelloJob class
    JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1").build();

    // Trigger the job to run on the next round minute
    Trigger trigger =
        newTrigger()
            .withIdentity("trigger1", "group1")
            .withIdentity(new TriggerKey("mytrigger"))
            .startAt(runTime)
            .build();

    // Tell quartz to schedule the job using our trigger
    sched.scheduleJob(job, trigger);
    log.info(job.getKey() + " will run at: " + runTime);

    // Start up the scheduler (nothing can actually run until the
    // scheduler has been started)
    sched.start();

    log.info("------- Started Scheduler -----------------");

    // wait long enough so that the scheduler as an opportunity to
    // run the job!
    log.info("------- Waiting 5 seconds... -------------");
    try {
      // wait 65 seconds to show job
      Thread.sleep(5L * 1000L);
      // executing...
    } catch (Exception e) {
    }

    // shut down the scheduler
    log.info("------- Shutting Down ---------------------");
    sched.shutdown(true);
    log.info("------- Shutdown Complete -----------------");
  }
 public void start(BootstrapContext ctx) throws ResourceAdapterInternalException {
   log.debug("start quartz!!!");
   // First we must get a reference to a scheduler
   SchedulerFactory sf = new StdSchedulerFactory();
   try {
     holder.set(ctx.getWorkManager());
     sched = sf.getScheduler();
     SecurityActions.startScheduler(sched);
   } catch (SchedulerException e) {
     throw new ResourceAdapterInternalException(e);
   } finally {
     holder.set(null);
   }
 }
예제 #14
0
  public static void ExecuteJob() throws Exception {

    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    Scheduler scheduler = schedulerFactory.getScheduler();

    JobDetail jobService1 = new JobDetail("jobService1", "daemon", JobService1.class);
    CronTrigger jobTrigger1 = new CronTrigger("jobTrigger1", "daemonTrigger1", "*/5 * * * * ?");
    scheduler.scheduleJob(jobService1, jobTrigger1);

    JobDetail jobService2 = new JobDetail("jobService2", "daemon", JobService2.class);
    CronTrigger jobTrigger2 = new CronTrigger("jobTrigger2", "daemonTrigger2", "*/5 * * * * ?");
    scheduler.scheduleJob(jobService2, jobTrigger2);

    scheduler.start();
  }
예제 #15
0
 /**
  * 添加一个定时任务
  *
  * @param jobName 任务名
  * @param jobGroupName 任务组名
  * @param triggerName 触发器名
  * @param triggerGroupName 触发器组名
  * @param job 任务
  * @param cronExpression 时间设置,参考quartz说明文档
  */
 public static void addJob(
     String jobName,
     String jobGroupName,
     String triggerName,
     String triggerGroupName,
     Job job,
     String cronExpression)
     throws SchedulerException, ParseException {
   if (StringUtils.isBlank(jobGroupName)) {
     jobGroupName = JOB_GROUP_NAME;
   }
   if (StringUtils.isBlank(triggerGroupName)) {
     triggerGroupName = TRIGGER_GROUP_NAME;
   }
   Scheduler sched = sf.getScheduler();
   //	       JobDetail jobDetail = new JobDetail(jobName, jobGroupName,
   // job.getClass());//任务名,任务组,任务执行类
   //	       CronTrigger  trigger = new
   // CronTrigger(jobName,triggerGroupName,cronExpression);//触发器名,触发器组,cron表达式
   //	       sched.scheduleJob(jobDetail,trigger);
   // 启动
   if (!sched.isShutdown()) {
     sched.start();
   }
 }
예제 #16
0
  @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();
  }
예제 #17
0
  public void init() {

    try {
      schedFact = new org.quartz.impl.StdSchedulerFactory();
      sched = schedFact.getScheduler();
      if (sched.isStarted() == false) sched.start();

      MongoCollection<BsonDocument> collection =
          Configuration.mongoDatabase.getCollection("Subscription", BsonDocument.class);

      Iterator<BsonDocument> subIterator = collection.find(BsonDocument.class).iterator();
      MongoQueryService queryService = new MongoQueryService();
      while (subIterator.hasNext()) {
        BsonDocument sub = subIterator.next();
        SubscriptionType subscription = new SubscriptionType(sub);
        if (subscription.getSchedule() != null && subscription.getTrigger() == null) {
          queryService.addScheduleToQuartz(subscription);
        } else if (subscription.getSchedule() == null && subscription.getTrigger() != null) {
          TriggerEngine.addTriggerSubscription(
              sub.getString("subscriptionID").getValue(), subscription);
        }
      }

    } catch (SchedulerException e) {
      Configuration.logger.log(Level.ERROR, e.toString());
    }
  }
예제 #18
0
 /**
  * 移除一个任务
  *
  * @param jobName
  * @param jobGroupName
  * @param triggerName
  * @param triggerGroupName
  * @throws SchedulerException
  */
 public void removeJob(
     String jobName, String jobGroupName, String triggerName, String triggerGroupName)
     throws SchedulerException {
   Scheduler sched = sf.getScheduler();
   sched.pauseTrigger(triggerName, triggerGroupName); // 停止触发器
   sched.unscheduleJob(triggerName, triggerGroupName); // 移除触发器
   sched.deleteJob(jobName, jobGroupName); // 删除任务
 }
예제 #19
0
  @Override
  @Async
  public Future<Object> initiateBatch()
      throws InterruptedException, JobParametersInvalidException, SpartanPersistenceException,
          SchedulerException, ClassNotFoundException {
    System.out.println("Came in batch initiate at " + new java.util.Date());

    Thread.sleep(60000);
    boolean initiate = true;
    SchedulerFactory factory = new StdSchedulerFactory();
    Scheduler scheduler = factory.getScheduler();
    // read from tbl_job and tbl_job_scheduler if any job is scheduled
    // or not
    while (initiate) {
      List<JobDetails> jobList = jobDetailsRepository.getAllJobs();

      for (JobDetails job : jobList) {
        try {
          jobInitiator.runJob(job, scheduler);
          /* Set current failed status of job */
          job.setJobStarted();
          jobDetailsRepository.updateJobDetails(job);
          System.out.println("CURRENT STATUS :" + job.getCurrentStatus());
        } catch (JobRestartException | JobInstanceAlreadyCompleteException e) {
          /* Set current failed status of job */
          job.setJobFailed();
          jobDetailsRepository.updateJobDetails(job);
          System.out.println("CURRENT STATUS :" + job.getCurrentStatus());
          e.printStackTrace();
        } catch (JobExecutionAlreadyRunningException ex) {
          /* Set current failed status of job */
          job.setJobAlreadyRunning();
          jobDetailsRepository.updateJobDetails(job);
          System.out.println("CURRENT STATUS :" + job.getCurrentStatus());
        }
      }
      //	if (jobList.size() > 0) {
      Thread.sleep(300000);
      //		}
    }

    return new AsyncResult<Object>("");
  }
예제 #20
0
 public Scheduler getScheduler() {
   if (scheduler == null) {
     try {
       scheduler = factory.getScheduler();
     } catch (SchedulerException e) {
       LOG.error("Exception occurred retrieving the scheduler instance.", e);
     }
   }
   return scheduler;
 }
예제 #21
0
  public void schedule() throws Exception {

    logger.info("Start of scheduling fixtures....");

    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();
    JobDetail job =
        newJob(DailyFixtureJob.class).withIdentity("DailyFixtureJob", "Fixtures").build();

    CronTrigger trigger =
        newTrigger()
            .withIdentity("fixture", "Fixtures")
            .withSchedule(dailyAtHourAndMinute(17, 12))
            .forJob(job.getKey())
            .build();

    sched.scheduleJob(job, trigger);
    sched.start();

    logger.info("End of scheduling fixtures: success");
  }
예제 #22
0
  public static void main(String[] args) {
    // Configure Job
    JobDetail jobDetail =
        JobBuilder.newJob(HelloWorldJob.class).withIdentity("HelloWorldJob").build();

    // Configure Trigger
    Trigger trigger =
        TriggerBuilder.newTrigger()
            .withSchedule(
                SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever())
            .build();

    // Start Scheduler
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();

    try {
      Scheduler scheduler = schedulerFactory.getScheduler();
      scheduler.start();
      scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
  }
예제 #23
0
 @Override
 public boolean start() {
   sf = new StdSchedulerFactory();
   try {
     sched = sf.getScheduler();
   } catch (SchedulerException e) {
     new RuntimeException(e);
   }
   loadProperties();
   Enumeration<?> enums = properties.keys();
   while (enums.hasMoreElements()) {
     String key = enums.nextElement() + "";
     if (!key.endsWith("job")) {
       continue;
     }
     String cronKey = key.substring(0, key.lastIndexOf("job")) + "cron";
     String enable = key.substring(0, key.lastIndexOf("job")) + "enable";
     if (!isEnableJob(enable)) {
       continue;
     }
     String jobClassName = properties.get(key) + "";
     String jobCronExp = properties.getProperty(cronKey) + "";
     Class clazz;
     try {
       clazz = Class.forName(jobClassName);
     } catch (ClassNotFoundException e) {
       throw new RuntimeException(e);
     }
     JobDetail job = newJob(clazz).withIdentity(jobClassName, jobClassName).build();
     CronTrigger trigger =
         newTrigger()
             .withIdentity(jobClassName, jobClassName)
             .withSchedule(cronSchedule(jobCronExp))
             .build();
     Date ft = null;
     try {
       ft = sched.scheduleJob(job, trigger);
       sched.start();
     } catch (SchedulerException e) {
       new RuntimeException(e);
     }
     System.out.println(
         job.getKey()
             + " has been scheduled to run at: "
             + ft
             + " and repeat based on expression: "
             + trigger.getCronExpression());
   }
   return true;
 }
예제 #24
0
 /**
  * 修改一个任务的触发时间
  *
  * @param triggerName
  * @param triggerGroupName
  * @param time
  * @throws SchedulerException
  * @throws ParseException
  */
 public void modifyJobTime(String triggerName, String triggerGroupName)
     throws SchedulerException, ParseException {
   Scheduler sched = sf.getScheduler();
   Trigger trigger = sched.getTrigger(triggerName, triggerGroupName);
   if (trigger != null) {
     /* CronTrigger  ct = (CronTrigger)trigger;
     //修改时间
     ct.setCronExpression(time);*/
     SimpleTrigger st = triggerManager.setSimpleTrigger((SimpleTrigger) trigger);
     // 重启触发器
     // sched.resumeTrigger(triggerName,triggerGroupName);
     sched.rescheduleJob(triggerName, triggerGroupName, st);
   }
 }
예제 #25
0
 /** 移除一个任务和触发器 */
 public static void removeJob(
     String jobName, String jobGroupName, String triggerName, String triggerGroupName)
     throws SchedulerException {
   if (StringUtils.isBlank(jobGroupName)) {
     jobGroupName = JOB_GROUP_NAME;
   }
   if (StringUtils.isBlank(triggerGroupName)) {
     triggerGroupName = TRIGGER_GROUP_NAME;
   }
   Scheduler sched = sf.getScheduler();
   //	       sched.pauseTrigger(triggerName,triggerGroupName);//停止触发器
   //	       sched.unscheduleJob(triggerName,triggerGroupName);//移除触发器
   //	       sched.deleteJob(jobName,jobGroupName);//删除任务
 }
예제 #26
0
 /**
  * 从Scheduler 移除当前的Job,修改Trigger
  *
  * @param jobDetail
  * @param time
  * @throws SchedulerException
  * @throws ParseException
  */
 public static void modifyJobTime(JobDetail jobDetail, String time)
     throws SchedulerException, ParseException {
   Scheduler sched = sf.getScheduler();
   Trigger trigger = sched.getTrigger(jobDetail.getName(), TRIGGER_GROUP_NAME);
   if (trigger != null) {
     CronTrigger ct = (CronTrigger) trigger;
     // 移除当前进程的Job
     sched.deleteJob(jobDetail.getName(), jobDetail.getGroup());
     // 修改Trigger
     ct.setCronExpression(time);
     System.out.println("CronTrigger getName " + ct.getJobName());
     // 重新调度jobDetail
     sched.scheduleJob(jobDetail, ct);
   }
 }
  @PostConstruct
  private void init() {
    ServletContext context =
        (ServletContext) (FacesContext.getCurrentInstance().getExternalContext().getContext());

    Object scheduleFactoryObject =
        context.getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);
    if (scheduleFactoryObject instanceof SchedulerFactory) {
      schedulerfactory = (SchedulerFactory) scheduleFactoryObject;
      try {
        scheduler = schedulerfactory.getScheduler();
      } catch (SchedulerException e) {
        e.printStackTrace();
      }
    }
  }
예제 #28
0
 /** 修改一个任务的触发时间 */
 public static void modifyJobTime(
     String triggerName, String triggerGroupName, String cronExpression)
     throws SchedulerException, ParseException {
   if (StringUtils.isBlank(triggerGroupName)) {
     triggerGroupName = TRIGGER_GROUP_NAME;
   }
   Scheduler sched = sf.getScheduler();
   // Trigger trigger = sched.getTrigger(triggerName,triggerGroupName);
   //	       if(trigger != null){
   //	           CronTrigger ct = (CronTrigger)trigger;
   //	           //修改时间
   //	           ct.setCronExpression(cronExpression);
   //	           //重启触发器
   //	           sched.resumeTrigger(triggerName,triggerGroupName);
   //	       }
 }
예제 #29
0
  public static void startJob(String jobName, Job job, String time)
      throws SchedulerException, ParseException {
    Scheduler sched = sf.getScheduler();

    JobDetail jobDetail = new JobDetail();
    jobDetail.setName(jobName);
    jobDetail.setGroup(JOB_GROUP_NAME);
    jobDetail.setJobClass(job.getClass());

    CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);
    trigger.setCronExpression(time);
    sched.scheduleJob(jobDetail, trigger);

    if (!sched.isShutdown()) {
      sched.start();
    }
  }
예제 #30
0
 public void doInitialise() throws InitialisationException {
   super.doInitialise();
   try {
     if (scheduler == null) {
       if (factory == null) {
         Object[] args = null;
         if (factoryProperties != null) {
           args = new Object[] {factoryProperties};
         }
         factory = (SchedulerFactory) ClassHelper.instanciateClass(factoryClassName, args);
       }
       scheduler = factory.getScheduler();
     }
   } catch (Exception e) {
     throw new InitialisationException(
         new Message(Messages.INITIALISATION_FAILURE_X, "Quartz provider"), e);
   }
 }