Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to cleanup Quartz Jobs on shutdown in Java?

$
0
0
  1. /**
  2. * Shutdown the scheduler
  3.  */
  4. privatevoid 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. }

Viewing all articles
Browse latest Browse all 178

Trending Articles