Breaking News
Home / Java / Java Snippets / How to cleanup Quartz Jobs on shutdown in Java?

How to cleanup Quartz Jobs on shutdown in Java?

  1. /**
  2. * Shutdown the scheduler
  3.  */
  4. private void shutdownScheduler() {
  5.  
  6. try {
  7.    log.info("Performing Job Resources CleanUp");
  8.  
  9. Scheduler scheduler = SchedulerManager.getInstance().getScheduler();
  10.  if (scheduler != null) {
  11.    List jobExeContextList =  scheduler.getCurrentlyExecutingJobs();
  12.    log.info("There are " + jobExeContextList.size() + " running
  13.   jobs at shutdown.");
  14.    Iterator it = jobExeContextList.iterator();
  15.    while (it.hasNext()) {
  16. JobExecutionContext jobExeContext = (JobExecutionContext) it.next();
  17.    BasicJob job = (BasicJob) jobExeContext.getJobInstance();
  18.         job.cleanup();
  19.         }
  20.         log.info("Shutting down Quartz Scheduler…");
  21.         scheduler.shutdown(true);
  22.         } else {
  23.          log.info("Quartz Scheduler is not running");
  24.         }
  25.    } catch (Exception e) {
  26.    log.info("Error shutting down Quartz: " + e.getMessage(), e);
  27.  }
  28. }
[pb_builder]

Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Advertisment ad adsense adlogger