Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
1d317330
提交
1d317330
authored
8月 01, 2021
作者:
Weihua
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
小优化,没有任何功能性增强和bug修复,尝试初次pr
上级
ff73b1a5
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
71 行增加
和
101 行删除
+71
-101
XxlJobExecutor.java
...c/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
+47
-0
XxlJobSimpleExecutor.java
.../com/xxl/job/core/executor/impl/XxlJobSimpleExecutor.java
+2
-52
XxlJobSpringExecutor.java
.../com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java
+1
-48
SampleXxlJob.java
...com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
+21
-1
没有找到文件。
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
浏览文件 @
1d317330
...
...
@@ -3,6 +3,8 @@ package com.xxl.job.core.executor;
import
com.xxl.job.core.biz.AdminBiz
;
import
com.xxl.job.core.biz.client.AdminBizClient
;
import
com.xxl.job.core.handler.IJobHandler
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
com.xxl.job.core.handler.impl.MethodJobHandler
;
import
com.xxl.job.core.log.XxlJobFileAppender
;
import
com.xxl.job.core.server.EmbedServer
;
import
com.xxl.job.core.thread.JobLogFileCleanThread
;
...
...
@@ -13,6 +15,7 @@ import com.xxl.job.core.util.NetUtil;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -110,6 +113,50 @@ public class XxlJobExecutor {
}
protected
void
registerJobHandler
(
XxlJob
xxlJob
,
Object
bean
,
Method
executeMethod
){
if
(
xxlJob
==
null
)
{
return
;
}
String
name
=
xxlJob
.
value
();
//make and simplify the variables since they'll be called several times later
Class
<?>
clazz
=
bean
.
getClass
();
String
methodName
=
executeMethod
.
getName
();
if
(
name
.
trim
().
length
()
==
0
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler name invalid, for["
+
clazz
+
"#"
+
methodName
+
"] ."
);
}
if
(
loadJobHandler
(
name
)
!=
null
)
{
throw
new
RuntimeException
(
"xxl-job jobhandler["
+
name
+
"] naming conflicts."
);
}
executeMethod
.
setAccessible
(
true
);
// init and destroy
Method
initMethod
=
null
;
Method
destroyMethod
=
null
;
if
(
xxlJob
.
init
().
trim
().
length
()
>
0
)
{
try
{
initMethod
=
clazz
.
getDeclaredMethod
(
xxlJob
.
init
());
initMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler initMethod invalid, for["
+
clazz
+
"#"
+
methodName
+
"] ."
);
}
}
if
(
xxlJob
.
destroy
().
trim
().
length
()
>
0
)
{
try
{
destroyMethod
=
clazz
.
getDeclaredMethod
(
xxlJob
.
destroy
());
destroyMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler destroyMethod invalid, for["
+
clazz
+
"#"
+
methodName
+
"] ."
);
}
}
// registry jobhandler
registJobHandler
(
name
,
new
MethodJobHandler
(
bean
,
executeMethod
,
initMethod
,
destroyMethod
));
}
// ---------------------- admin-client (rpc invoker) ----------------------
private
static
List
<
AdminBiz
>
adminBizList
;
...
...
xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSimpleExecutor.java
浏览文件 @
1d317330
...
...
@@ -57,62 +57,12 @@ public class XxlJobSimpleExecutor extends XxlJobExecutor {
for
(
Object
bean:
xxlJobBeanList
)
{
// method
Method
[]
methods
=
bean
.
getClass
().
getDeclaredMethods
();
if
(
methods
==
null
||
methods
.
length
==
0
)
{
if
(
methods
.
length
==
0
)
{
continue
;
}
for
(
Method
executeMethod
:
methods
)
{
// anno
XxlJob
xxlJob
=
executeMethod
.
getAnnotation
(
XxlJob
.
class
);
if
(
xxlJob
==
null
)
{
continue
;
}
String
name
=
xxlJob
.
value
();
if
(
name
.
trim
().
length
()
==
0
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler name invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
if
(
loadJobHandler
(
name
)
!=
null
)
{
throw
new
RuntimeException
(
"xxl-job jobhandler["
+
name
+
"] naming conflicts."
);
}
// execute method
/*if (!(method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(String.class))) {
throw new RuntimeException("xxl-job method-jobhandler param-classtype invalid, for[" + bean.getClass() + "#" + method.getName() + "] , " +
"The correct method format like \" public ReturnT<String> execute(String param) \" .");
}
if (!method.getReturnType().isAssignableFrom(ReturnT.class)) {
throw new RuntimeException("xxl-job method-jobhandler return-classtype invalid, for[" + bean.getClass() + "#" + method.getName() + "] , " +
"The correct method format like \" public ReturnT<String> execute(String param) \" .");
}*/
executeMethod
.
setAccessible
(
true
);
// init and destory
Method
initMethod
=
null
;
Method
destroyMethod
=
null
;
if
(
xxlJob
.
init
().
trim
().
length
()
>
0
)
{
try
{
initMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
init
());
initMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler initMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
}
if
(
xxlJob
.
destroy
().
trim
().
length
()
>
0
)
{
try
{
destroyMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
destroy
());
destroyMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler destroyMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
}
// registry jobhandler
registJobHandler
(
name
,
new
MethodJobHandler
(
bean
,
executeMethod
,
initMethod
,
destroyMethod
));
registerJobHandler
(
xxlJob
,
bean
,
executeMethod
);
}
}
...
...
xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java
浏览文件 @
1d317330
...
...
@@ -105,56 +105,9 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
for
(
Map
.
Entry
<
Method
,
XxlJob
>
methodXxlJobEntry
:
annotatedMethods
.
entrySet
())
{
Method
executeMethod
=
methodXxlJobEntry
.
getKey
();
XxlJob
xxlJob
=
methodXxlJobEntry
.
getValue
();
if
(
xxlJob
==
null
)
{
continue
;
}
String
name
=
xxlJob
.
value
();
if
(
name
.
trim
().
length
()
==
0
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler name invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
if
(
loadJobHandler
(
name
)
!=
null
)
{
throw
new
RuntimeException
(
"xxl-job jobhandler["
+
name
+
"] naming conflicts."
);
}
// execute method
/*if (!(method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(String.class))) {
throw new RuntimeException("xxl-job method-jobhandler param-classtype invalid, for[" + bean.getClass() + "#" + method.getName() + "] , " +
"The correct method format like \" public ReturnT<String> execute(String param) \" .");
}
if (!method.getReturnType().isAssignableFrom(ReturnT.class)) {
throw new RuntimeException("xxl-job method-jobhandler return-classtype invalid, for[" + bean.getClass() + "#" + method.getName() + "] , " +
"The correct method format like \" public ReturnT<String> execute(String param) \" .");
}*/
executeMethod
.
setAccessible
(
true
);
// init and destory
Method
initMethod
=
null
;
Method
destroyMethod
=
null
;
if
(
xxlJob
.
init
().
trim
().
length
()
>
0
)
{
try
{
initMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
init
());
initMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler initMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
}
if
(
xxlJob
.
destroy
().
trim
().
length
()
>
0
)
{
try
{
destroyMethod
=
bean
.
getClass
().
getDeclaredMethod
(
xxlJob
.
destroy
());
destroyMethod
.
setAccessible
(
true
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"xxl-job method-jobhandler destroyMethod invalid, for["
+
bean
.
getClass
()
+
"#"
+
executeMethod
.
getName
()
+
"] ."
);
}
}
// registry jobhandler
registJobHandler
(
name
,
new
MethodJobHandler
(
bean
,
executeMethod
,
initMethod
,
destroyMethod
));
registerJobHandler
(
xxlJob
,
bean
,
executeMethod
);
}
}
}
// ---------------------- applicationContext ----------------------
...
...
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
浏览文件 @
1d317330
...
...
@@ -245,8 +245,28 @@ public class SampleXxlJob {
public
void
init
(){
logger
.
info
(
"init"
);
}
public
void
destroy
(){
logger
.
info
(
"destory"
);
logger
.
info
(
"destroy"
);
}
/**
* 6、生命周期任务示例:任务初始化与销毁时,支持private方法(但不推荐);
*/
@XxlJob
(
value
=
"demoJobHandler3"
,
init
=
"initForDemoJobHandler3"
,
destroy
=
"destroyForDemoJobHandler3"
)
public
void
demoJobHandler3
()
throws
Exception
{
XxlJobHelper
.
log
(
"XXL-JOB, Hello World."
);
}
private
void
initForDemoJobHandler3
(){
logger
.
info
(
"initForDemoJobHandler3"
);
}
/**
* 演示private方法也可以被访问且执行
*/
public
void
destroyForDemoJobHandler3
(){
logger
.
info
(
"destroyForDemoJobHandler3"
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论