1 16 17 package org.springframework.scheduling.quartz; 18 19 import org.quartz.SchedulerConfigException; 20 import org.quartz.simpl.SimpleThreadPool; 21 22 import org.springframework.beans.factory.DisposableBean; 23 import org.springframework.beans.factory.InitializingBean; 24 import org.springframework.scheduling.SchedulingException; 25 import org.springframework.scheduling.SchedulingTaskExecutor; 26 import org.springframework.util.Assert; 27 28 44 public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool 45 implements SchedulingTaskExecutor, InitializingBean, DisposableBean { 46 47 private boolean waitForJobsToCompleteOnShutdown = false; 48 49 50 55 public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) { 56 this.waitForJobsToCompleteOnShutdown = waitForJobsToCompleteOnShutdown; 57 } 58 59 public void afterPropertiesSet() throws SchedulerConfigException { 60 initialize(); 61 } 62 63 64 public void execute(Runnable task) { 65 Assert.notNull(task, "Runnable must not be null"); 66 if (!runInThread(task)) { 67 throw new SchedulingException("Quartz SimpleThreadPool already shut down"); 68 } 69 } 70 71 74 public boolean prefersShortLivedTasks() { 75 return true; 76 } 77 78 79 public void destroy() { 80 shutdown(this.waitForJobsToCompleteOnShutdown); 81 } 82 83 } 84 | Popular Tags |