提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.timer.jobhandler; |
懒 |
2 |
|
|
3 |
import com.xxl.job.core.biz.model.ReturnT; |
|
4 |
import com.xxl.job.core.handler.IJobHandler; |
|
5 |
import com.xxl.job.core.handler.annotation.JobHandler; |
|
6 |
import com.xxl.job.core.log.XxlJobLogger; |
|
7 |
|
|
8 |
import java.util.concurrent.TimeUnit; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* 任务Handler示例(Bean模式) |
|
13 |
* <p> |
|
14 |
* 开发步骤: |
|
15 |
* 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”; |
|
16 |
* 2、注册到Spring容器:添加“@Component”注解,被Spring容器扫描为Bean实例; |
|
17 |
* 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。 |
|
18 |
* 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; |
|
19 |
* |
|
20 |
* @author xuxueli 2015-12-19 19:43:36 |
|
21 |
*/ |
|
22 |
@JobHandler(value = "demoJobHandler") |
|
23 |
public class DemoJobHandler extends IJobHandler { |
|
24 |
|
|
25 |
@Override |
|
26 |
public ReturnT<String> execute(String param) throws Exception { |
|
27 |
XxlJobLogger.log("XXL-JOB, Hello World."); |
|
28 |
|
|
29 |
for (int i = 0; i < 5; i++) { |
|
30 |
XxlJobLogger.log("beat at:" + i); |
|
31 |
TimeUnit.SECONDS.sleep(2); |
|
32 |
} |
|
33 |
return SUCCESS; |
|
34 |
} |
|
35 |
|
|
36 |
} |