spring定时器注解的用法详解

来源:互联网 发布:不干胶排版软件 编辑:程序博客网 时间:2024/05/17 02:02

核心2步:

第一步:关于spring-mvc 配置文件的修改:

注:在配置文件的beans 里面加入一下内容:

1.1 标签的引入:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-4.1.xsd
1.2 注解的启动以及扫描包路径的配置
注:加在<mvc:annotation-driven> 标签的后面
<context:component-scan base-package="com.bonc.ioc.iot.scheduled" />
<task:annotation-driven scheduler="qbScheduler" mode="proxy"/><task:scheduler id="qbScheduler" pool-size="10"/>
第二步:Java代码注解-
@Component("iotParserTaskPre")public class IotParserTaskPre {    @Autowired    private IotParserServiceMapper iotParserServiceMapper;    @Scheduled(cron = "0/1 * * * * ?")//    @Scheduled(fixedRate = 1000*2)    public void getIsAbledParserTask(){        List<IotParserService> iotParserServiceList=iotParserServiceMapper.findParserTasks();        if(iotParserServiceList!=null&&!iotParserServiceList.isEmpty()){            //todo 1 根据查询得到的任务数量启动多线程            //todo 2 更新服务解析状态为(开始解析)            //todo 3 解析服务 (核心方法)            //todo 4 更新服务解析状态 (解析中)            //todo 5 保存解析数据            //todo 6 更新服务解析状态 (解析完成)        }    }}



原创粉丝点击