1 16 17 package org.springframework.scheduling.quartz; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.quartz.SchedulerConfigException; 22 import org.quartz.spi.ThreadPool; 23 24 import org.springframework.core.task.TaskExecutor; 25 import org.springframework.core.task.TaskRejectedException; 26 27 35 public class LocalTaskExecutorThreadPool implements ThreadPool { 36 37 38 protected final Log logger = LogFactory.getLog(getClass()); 39 40 private TaskExecutor taskExecutor; 41 42 43 public void initialize() throws SchedulerConfigException { 44 this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor(); 46 if (this.taskExecutor == null) { 47 throw new SchedulerConfigException( 48 "No local TaskExecutor found for configuration - " + 49 "'taskExecutor' property must be set on SchedulerFactoryBean"); 50 } 51 } 52 53 public void shutdown(boolean waitForJobsToComplete) { 54 } 55 56 public int getPoolSize() { 57 return -1; 58 } 59 60 61 public boolean runInThread(Runnable runnable) { 62 if (runnable == null) { 63 return false; 64 } 65 try { 66 this.taskExecutor.execute(runnable); 67 return true; 68 } 69 catch (TaskRejectedException ex) { 70 logger.error("Task has been rejected by TaskExecutor", ex); 71 return false; 72 } 73 } 74 75 public int blockForAvailableThreads() { 76 return 1; 82 } 83 84 } 85 | Popular Tags |