}
}
private Runnable createTask(TaskDefinition td) {
final MethodInvoker methodInvoker = new MethodInvoker();
final Long taskId = td.getId();
try {
methodInvoker.setTargetMethod(td.getMethodName());
Object bean = null;
if(StringUtils.isNotEmpty(td.getBeanName())) {
bean = applicationContext.getBean(td.getBeanName());
} else {
bean = applicationContext.getAutowireCapableBeanFactory().createBean(Class.forName(td.getBeanClass()));
}
methodInvoker.setTargetObject(bean);
methodInvoker.prepare();
} catch (Exception e) {
throw new DynamicTaskException("create task runnable error, task id is : " + taskId, e);
}
return new Runnable() {
@Override
public void run() {
try {
methodInvoker.invoke();
} catch (Exception e) {
logger.error("run dynamic task error, task id is:" + taskId, e);
throw new DynamicTaskException("run dynamic task error, task id is:" + taskId, e);
}
}