我正在使用Spring的SchedulerFactoryBean來動態安排工作。 這裏是我的Spring配置:春季石英工作未開始
@Configuration
public class SpringConfigBean {
@Bean
public DataSource dataSource() throws NamingException{
InitialContext ctx = new InitialContext();
DataSource source = (DataSource) ctx.lookup(dataSourceName);
return source;
}
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws NamingException {
SchedulerFactoryBean schedulerFactoryBean = null;
try {
schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setDataSource(dataSource());
schedulerFactoryBean.setQuartzProperties(com.orca.integration.plugins.vs.broadpeak.admin.utils.Configuration.getQuartzProperties());
schedulerFactoryBean.setAutoStartup(false);
} catch (SchedulingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return schedulerFactoryBean;
}
}
這裏是我的工作:
@Component
public class MyJob extends QuartzJobBean {
@Override
public void executeInternal(JobExecutionContext context) throws JobExecutionException {
System.out.println("Start job...");
}
}
這是我在動態調度任務:
@Component
public class MyManager {
@Autowired
private SchedulerFactoryBean schedulerFactoryBean;
public void myMethod(String text, Calendar startDate) {
logger.debug("BroadpeakDistributionManager.startRecordingChannel(); Parameters: recording channel ID=" + recordingChannel.getExternalId());
// StartRecordJob.scheduleMe(text, startDate, "Start");
JobDetailBean jobDetailBean = new JobDetailBean();
jobDetailBean.setJobClass(MyJob.class);
jobDetailBean.setName("name");
jobDetailBean.afterPropertiesSet();
SimpleTriggerBean simpleTriggerBean = new SimpleTriggerBean();
simpleTriggerBean.setJobDetail(jobDetailBean);
simpleTriggerBean.setName("Name");
simpleTriggerBean.setStartTime(startDate.getTime());
try {
simpleTriggerBean.afterPropertiesSet();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
schedulerFactoryBean.setTriggers(new Trigger[] {simpleTriggerBean});
schedulerFactoryBean.start();
}
}
的工作沒有開始。 我在做什麼錯?
誰執行myMethod的? – sinuhepop 2012-07-19 14:03:57