congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Scheduler
Code IndexAdd Tabnine to your IDE (free)

How to use
Scheduler
in
org.quartz.core

Best Java code snippets using org.quartz.core.Scheduler (Showing top 20 results out of 315)

origin: org.mycontroller.standalone/mycontroller-core

public static synchronized Long nextFireTime(String _name, Integer _id) {
  String _triggerName = getCronTriggerName(getTimerJobName(_name, _id));
  try {
    return SundialJobScheduler.getScheduler().getTrigger(_triggerName).getNextFireTime().getTime();
  } catch (Exception ex) {
    _logger.error("Error when fetching trigger[{}] next exeuction status", _triggerName, ex);
  }
  return null;
}
origin: com.xeiam/sundial

/**
 * Removes a Job matching the given Job Name
 *
 * @param jobName
 */
public static void removeJob(String jobName) {
 try {
  getScheduler().deleteJob(jobName);
 } catch (SchedulerException e) {
  logger.error("ERROR REMOVING JOB!!!", e);
 }
}
origin: com.xeiam/sundial

@Override
public void start() {
 try {
  XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(scheduler.getCascadingClassLoadHelper());
  processor.processFile(XMLSchedulingDataProcessor.QUARTZ_XML_DEFAULT_FILE_NAME, failOnFileNotFound);
  processor.scheduleJobs(getScheduler());
 } catch (Exception e) {
  logger.error("Error scheduling jobs: " + e.getMessage(), e);
 }
}
origin: com.xeiam/sundial

/**
 * Generates a Map of all Job names with corresponding Triggers
 *
 * @return
 */
public static Map<String, List<Trigger>> getAllJobsAndTriggers() {
 Map<String, List<Trigger>> allJobsMap = new TreeMap<String, List<Trigger>>();
 try {
  Set<String> allJobKeys = getScheduler().getJobKeys();
  for (String jobKey : allJobKeys) {
   List<Trigger> triggers = getScheduler().getTriggersOfJob(jobKey);
   allJobsMap.put(jobKey, triggers);
  }
 } catch (SchedulerException e) {
  logger.error("COULD NOT GET JOB NAMES!!!", e);
 }
 return allJobsMap;
}
origin: com.xeiam/sundial

logger.info("Scheduled job: {} ", jobDetail);
sched.addJob(jobDetail);
Trigger dupeT = sched.getTrigger(trigger.getName());
if (dupeT != null) { // if trigger with name already exists
 sched.rescheduleJob(trigger.getName(), trigger);
} else {
 logger.debug("Scheduling job: " + trigger.getJobName() + " with trigger: " + trigger.getName());
  sched.scheduleJob(trigger);
 } catch (ObjectAlreadyExistsException e) {
  logger.debug("Adding trigger: " + trigger.getName() + " for job: " + trigger.getJobName() + " failed because the trigger already existed.");
origin: org.knowm/sundial

Set<Class<? extends Job>> scheduledClasses = scheduler.getCascadingClassLoadHelper().getJobClasses(packageName);
  try {
   trigger = buildCronTrigger(cronTrigger, jobClass.getSimpleName());
   scheduler.scheduleJob(jobDetail, trigger);
   logger.info("Scheduled job: {} with trigger: {}", jobDetail, trigger);
  } catch (Exception e) {
  try {
   trigger = buildSimpleTrigger(simpleTrigger, jobClass.getSimpleName());
   scheduler.scheduleJob(job, trigger);
   logger.info("Scheduled job {} with trigger {}", job, trigger);
  } catch (Exception e) {
origin: com.xeiam/sundial

 /**
  * Halts the Scheduler's firing of Triggers, and cleans up all resources associated with the Scheduler.
  */
 public static void shutdown() {

  logger.debug("shutdown() called.");

  try {
   getScheduler().shutdown(true);
  } catch (Exception e) {
   logger.error("COULD NOT SHUTDOWN SCHEDULER!!!", e);
  }
 }
}
origin: com.xeiam/sundial

public static boolean isJobRunning(String jobName) {
 try {
  List<JobExecutionContext> currentlyExecutingJobs = getScheduler().getCurrentlyExecutingJobs();
  for (JobExecutionContext jobExecutionContext : currentlyExecutingJobs) {
   String currentlyExecutingJobName = jobExecutionContext.getJobDetail().getName();
   if (currentlyExecutingJobName.equals(jobName)) {
    logger.debug("Matching running Job found!");
    return true;
   }
  }
 } catch (SchedulerException e) {
  logger.error("ERROR CHECKING RUNNING JOB!!!", e);
 }
 logger.debug("Matching running NOT Job found!");
 return false;
}
origin: com.xeiam/sundial

/**
 * Adds a Job to the scheduler. Replaces a matching existing Job.
 *
 * @param jobName
 * @param jobClassName
 * @param params Set this null if there are no params
 * @param isConcurrencyAllowed
 */
public static void addJob(String jobName, String jobClassName, Map<String, Object> params, boolean isConcurrencyAllowed) {
 try {
  Class<? extends Job> jobClass = getScheduler().getCascadingClassLoadHelper().loadClass(jobClassName);
  JobDataMap jobDataMap = new JobDataMap();
  if (params != null) {
   for (Entry<String, Object> entry : params.entrySet()) {
    jobDataMap.put(entry.getKey(), entry.getValue());
   }
  }
  JobDetail jobDetail = newJobBuilder(jobClass).withIdentity(jobName).usingJobData(jobDataMap).isConcurrencyAllowed(isConcurrencyAllowed).build();
  getScheduler().addJob(jobDetail);
 } catch (SchedulerException e) {
  logger.error("ERROR ADDING JOB!!!", e);
 } catch (ClassNotFoundException e) {
  logger.error("ERROR ADDING JOB!!!", e);
 }
}
origin: com.xeiam/sundial

/**
 * @param triggerName
 * @param jobName
 * @param cronExpression
 * @param startTime
 * @param endTime
 */
public static void addCronTrigger(String triggerName, String jobName, String cronExpression, Date startTime, Date endTime) {
 try {
   CronTriggerBuilder cronTriggerBuilder = cronTriggerBuilder(cronExpression);
   cronTriggerBuilder.withIdentity(triggerName).forJob(jobName).withPriority(Trigger.DEFAULT_PRIORITY);
   if(startTime != null){
     cronTriggerBuilder.startAt(startTime);
   }
   if(endTime != null){
     cronTriggerBuilder.endAt(endTime);
   }
  OperableTrigger trigger = cronTriggerBuilder.build();
    getScheduler().scheduleJob(trigger);
 } catch (SchedulerException e) {
  logger.error("ERROR ADDING CRON TRIGGER!!!", e);
 } catch (ParseException e) {
  logger.error("ERROR ADDING CRON TRIGGER!!!", e);
 }
}
origin: com.xeiam/sundial

/**
 * Generates an alphabetically sorted List of all Job names in the DEFAULT job group
 *
 * @return
 */
public static List<String> getAllJobNames() {
 List<String> allJobNames = new ArrayList<String>();
 try {
  Set<String> allJobKeys = getScheduler().getJobKeys();
  for (String jobKey : allJobKeys) {
   allJobNames.add(jobKey);
  }
 } catch (SchedulerException e) {
  logger.error("COULD NOT GET JOB NAMES!!!", e);
 }
 Collections.sort(allJobNames);
 return allJobNames;
}
origin: org.knowm/sundial

/**
 * Adds a Job to the scheduler. Replaces a matching existing Job.
 *
 * @param jobName
 * @param jobClass
 * @param params Set this null if there are no params
 * @param isConcurrencyAllowed
 */
public static void addJob(String jobName, Class<? extends Job> jobClass, Map<String, Object> params, boolean isConcurrencyAllowed)
  throws SundialSchedulerException {
 try {
  JobDataMap jobDataMap = new JobDataMap();
  if (params != null) {
   for (Entry<String, Object> entry : params.entrySet()) {
    jobDataMap.put(entry.getKey(), entry.getValue());
   }
  }
  JobDetail jobDetail = newJobBuilder(jobClass).withIdentity(jobName).usingJobData(jobDataMap).isConcurrencyAllowed(isConcurrencyAllowed).build();
  getScheduler().addJob(jobDetail);
 } catch (SchedulerException e) {
  logger.error("ERROR ADDING JOB!!!", e);
  throw new SundialSchedulerException("ERROR ADDING JOB!!!", e);
 }
}
origin: org.knowm/sundial

logger.info("Scheduled job: {} ", jobDetail);
sched.addJob(jobDetail);
Trigger dupeT = sched.getTrigger(trigger.getName());
if (dupeT != null) { // if trigger with name already exists
 sched.rescheduleJob(trigger.getName(), trigger);
} else {
 logger.debug("Scheduling job: " + trigger.getJobName() + " with trigger: " + trigger.getName());
  sched.scheduleJob(trigger);
 } catch (ObjectAlreadyExistsException e) {
  logger.debug("Adding trigger: " + trigger.getName() + " for job: " + trigger.getJobName() + " failed because the trigger already existed.");
origin: org.knowm/sundial

/**
 * Generates a Map of all Job names with corresponding Triggers
 *
 * @return
 */
public static Map<String, List<Trigger>> getAllJobsAndTriggers() throws SundialSchedulerException {
 Map<String, List<Trigger>> allJobsMap = new TreeMap<String, List<Trigger>>();
 try {
  Set<String> allJobKeys = getScheduler().getJobKeys();
  for (String jobKey : allJobKeys) {
   List<Trigger> triggers = getScheduler().getTriggersOfJob(jobKey);
   allJobsMap.put(jobKey, triggers);
  }
 } catch (SchedulerException e) {
  throw new SundialSchedulerException("COULD NOT GET JOB NAMES!!!", e);
 }
 return allJobsMap;
}
origin: com.xeiam/sundial

Set<Class<? extends Job>> scheduledClasses = scheduler.getCascadingClassLoadHelper().getJobClasses(packageName);
  try {
   trigger = buildCronTrigger(cronTrigger, jobClass.getSimpleName());
   scheduler.scheduleJob(jobDetail, trigger);
   logger.info("Scheduled job: {} with trigger: {}", jobDetail, trigger);
  } catch (Exception e) {
  try {
   trigger = buildSimpleTrigger(simpleTrigger, jobClass.getSimpleName());
   scheduler.scheduleJob(job, trigger);
   logger.info("Scheduled job {} with trigger {}", job, trigger);
  } catch (Exception e) {
origin: org.knowm/sundial

 @Override
 public void run() {
  logger.info("Shutting down Quartz...");
  try {
   scheduler.shutdown(isCleanShutdown());
  } catch (SchedulerException e) {
   logger.info("Error shutting down Quartz: " + e.getMessage(), e);
  }
 }
};
origin: knowm/Sundial

public static boolean isJobRunning(String jobName) throws SundialSchedulerException {
 try {
  List<JobExecutionContext> currentlyExecutingJobs = getScheduler().getCurrentlyExecutingJobs();
  for (JobExecutionContext jobExecutionContext : currentlyExecutingJobs) {
   String currentlyExecutingJobName = jobExecutionContext.getJobDetail().getName();
   if (currentlyExecutingJobName.equals(jobName)) {
    logger.debug("Matching running Job found!");
    return true;
   }
  }
 } catch (SchedulerException e) {
  throw new SundialSchedulerException("ERROR CHECKING RUNNING JOB!!!", e);
 }
 logger.debug("Matching running NOT Job found!");
 return false;
}
origin: com.xeiam/sundial

/**
 * @param triggerName
 * @param jobName
 * @param repeatCount
 * @param repeatInterval
 * @param startTime
 * @param endTime
 */
public static void addSimpleTrigger(String triggerName, String jobName, int repeatCount, long repeatInterval, Date startTime, Date endTime) {
 try {
   SimpleTriggerBuilder simpleTriggerBuilder = simpleTriggerBuilder();
   simpleTriggerBuilder.withRepeatCount(repeatCount).withIntervalInMilliseconds(repeatInterval).withIdentity(triggerName).forJob(jobName);
   if(startTime != null){
     simpleTriggerBuilder.startAt(startTime);
   }
   if(endTime != null){
     simpleTriggerBuilder.endAt(endTime);
   }
  OperableTrigger trigger = simpleTriggerBuilder.build();
  getScheduler().scheduleJob(trigger);
 } catch (SchedulerException e) {
  logger.error("ERROR ADDING CRON TRIGGER!!!", e);
 }
}
origin: org.knowm/sundial

/**
 * Generates an alphabetically sorted List of all Job names in the DEFAULT job group
 *
 * @return
 */
public static List<String> getAllJobNames() throws SundialSchedulerException {
 List<String> allJobNames = new ArrayList<String>();
 try {
  Set<String> allJobKeys = getScheduler().getJobKeys();
  for (String jobKey : allJobKeys) {
   allJobNames.add(jobKey);
  }
 } catch (SchedulerException e) {
  throw new SundialSchedulerException("COULD NOT GET JOB NAMES!!!", e);
 }
 Collections.sort(allJobNames);
 return allJobNames;
}
origin: knowm/Sundial

    .build();
getScheduler().addJob(jobDetail);
org.quartz.coreScheduler

Javadoc

This is the main interface of a Quartz Scheduler.

A Scheduler maintains a registry of org.quartz.jobs.JobDetails and Triggers. Once registered, the Scheduler is responsible for executing Job s when their associated Trigger s fire (when their scheduled time arrives).

Scheduler instances are produced by a SchedulerFactory. A scheduler that has already been created/initialized can be found and used through the same factory that produced it. After a Scheduler has been created, it is in "stand-by" mode, and must have its start() method called before it will fire any Job s.

Job s are to be created by the 'client program', by defining a class that implements the org.quartz.jobs.Job interface. JobDetail objects are then created (also by the client) to define a individual instances of the Job . JobDetail instances can then be registered with the Scheduler via the scheduleJob(JobDetail, Trigger) or addJob(JobDetail, boolean) method.

Trigger s can then be defined to fire individual Job instances based on given schedules. SimpleTrigger s are most useful for one-time firings, or firing at an exact moment in time, with N repeats with a given delay between them. CronTrigger s allow scheduling based on time of day, day of week, day of month, and month of year.

Job s and Trigger s have a name and group associated with them, which should uniquely identify them within a single Scheduler. The 'group' feature may be useful for creating logical groupings or categorizations of Jobs s and Triggerss. If you don't have need for assigning a group to a given Jobs of Triggers, then you can use the DEFAULT_GROUP constant defined on this interface.

Stored Job s can also be 'manually' triggered through the use of the triggerJob(String jobName, String jobGroup) function.

Client programs may also be interested in the 'listener' interfaces that are available from Quartz. The JobListener interface provides notifications of Job executions. The TriggerListener interface provides notifications of Trigger firings. The SchedulerListener interface provides notifications of Scheduler events and errors. Listeners can be associated with local schedulers through the ListenerManager interface.

The setup/configuration of a Scheduler instance is very customizable. Please consult the documentation distributed with Quartz.

Most used methods

  • getTrigger
    Get the Trigger instance with the given key. The returned Trigger object will be a snap-shot of the
  • addJob
    Add the given Job to the Scheduler - with no associated Trigger. The Job will be 'dormant' until it
  • deleteJob
    Delete the identified Job from the Scheduler - and any associated Triggers.
  • getCascadingClassLoadHelper
  • getCurrentlyExecutingJobs
    Return a list of JobExecutionContext objects that represent all currently executing Jobs in this Sch
  • getJobKeys
    Get the keys of all the org.quartz.jobs.JobDetails in the matching groups.
  • getTriggersOfJob
    Get all Trigger s that are associated with the identified org.quartz.jobs.JobDetail. The returned T
  • rescheduleJob
    Remove (delete) the org.quartz.triggers.OperableTrigger with the given key, and store the new given
  • scheduleJob
    Schedule the given org.quartz.triggers.OperableTrigger with the Job identified by the Trigger's sett
  • shutdown
    Halts the Scheduler's firing of Triggers, and cleans up all resources associated with the Scheduler.
  • start
    Starts the Scheduler's threads that fire Triggers. When a scheduler is first created it is in "stand
  • startDelayed
    Calls {#start()} after the indicated number of seconds. (This call does not block). This can be usef
  • start,
  • startDelayed,
  • triggerJob,
  • unscheduleJob,
  • getListenerManager

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onCreateOptionsMenu (Activity)
  • getExternalFilesDir (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Menu (java.awt)
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now