Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hel-developer-guide
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Spencer Chang
hel-developer-guide
Commits
ed2d2d7e
Commit
ed2d2d7e
authored
Jul 31, 2017
by
midKingKing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates 框架功能描述/计划任务.md
Auto commit by GitBook Editor
parent
3a3d6ac3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
1 deletion
+42
-1
计划任务.md
框架功能描述/计划任务.md
+42
-1
No files found.
框架功能描述/计划任务.md
View file @
ed2d2d7e
...
@@ -40,5 +40,46 @@
...
@@ -40,5 +40,46 @@
#### 2.3 任务类的编写
#### 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可以拿到你在任务配置中定义的参数
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment