Commit ed2d2d7e authored by midKingKing's avatar midKingKing

Updates 框架功能描述/计划任务.md

Auto commit by GitBook Editor
parent 3a3d6ac3
......@@ -40,5 +40,46 @@
#### 2.3 任务类的编写
想要自定义一个job,必须要继承一个抽象类AbstractJob,然后在`safeExecute()`方法中执行
想要自定义一个job,必须要继承一个抽象类AbstractJob,然后在`safeExecute()`方法中执行业务代码,示例代码如下:
```java
public class demoJob extends AbstractJob{
@Autowired
private xxxService service;//业务类
@Override
public void safeExecute(JobExecutionContext jobExecutionContext) throws Exception {
//map中可以获取上方定义的参数,key为参数名称,value为参数值
JobDataMap map = jobExecutionContext.getMergedJobDataMap();
try {
service.dosomething();
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
}
exception = e;
throw e;
}
if (exception != null) {
setExecutionSummary(exception.getClass().getName() + ":" + exception.getMessage());
} else {
setExecutionSummary("执行完成!" );
}
}
@Override
public boolean isRefireImmediatelyWhenException() {
//任务发生异常时候进行的动作
//false 挂起当前JOB等待处理
//true 继续执行
return false;
}
}
```
注意:
调用`setExecutionSummary()`方法可以在执行记录中,记录你的业务数据的记录,或者抛出的异常的具体信息。
在上下文中获取JobDataMap可以拿到你在任务配置中定义的参数
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment