/** This method adds the {@link #JOBKEY_DATABASE_UPDATE_INSTANT} job to the scheduler. */
 public void startInstantDatabaseUpdate() {
   try {
     if (!sched.checkExists(JOBKEY_DATABASE_UPDATE_INSTANT)) {
       sched.addJob(instantDatabaseUpdateJob, true);
     }
     if (!QuartzUpdateDatabaseJob.IS_RUNNING) {
       sched.triggerJob(JOBKEY_DATABASE_UPDATE_INSTANT);
     }
   } catch (SchedulerException ex) {
     Logger.getLogger(QuartzSchedulerController.class.getName()).log(Level.SEVERE, null, ex);
     throw new WebApplicationException(PreparedServerResponses.ERROR_SCHEDULER);
   }
 }
Example #2
0
  private void startJobs() {
    try {
      // Get a new scheduler
      scheduler = new StdSchedulerFactory().getScheduler();
      // Start it up. This won't start any jobs though.
      scheduler.start();

      for (GuanxiJobConfig gxJob : gxJobs) {
        // Need a new JobDetail to hold custom data to send to the job we're controlling
        JobDetail jobDetail =
            new JobDetail(
                gxJob.getKey(), Scheduler.DEFAULT_GROUP, Class.forName(gxJob.getJobClass()));

        // Create a new JobDataMap for custom data to be sent to the job...
        JobDataMap jobDataMap = new JobDataMap();
        // ...and add the job's custom config object
        jobDataMap.put(GuanxiJobConfig.JOB_KEY_JOB_CONFIG, gxJob);

        // Put the job's custom data in it's JobDetail
        jobDetail.setJobDataMap(jobDataMap);

        /* Tell the scheduler when this job will run. Nothing will happen
         * until the start method is called.
         */
        Trigger trigger =
            new CronTrigger(gxJob.getKey(), Scheduler.DEFAULT_GROUP, gxJob.getCronLine());

        // Start the job
        scheduler.scheduleJob(jobDetail, trigger);

        if (gxJob.isStartImmediately()) {
          scheduler.triggerJob(gxJob.getKey(), Scheduler.DEFAULT_GROUP);
        }
      }
    } catch (ClassNotFoundException cnfe) {
      logger.error("Error locating job class", cnfe);
    } catch (SchedulerException se) {
      logger.error("Job scheduling error", se);
    } catch (ParseException pe) {
      logger.error("Error parsing job cronline", pe);
    }
  }