核心2步:
第一步:关于spring-mvc 配置文件的修改:
注:在配置文件的beans 里面加入一下内容:
1.1 标签的引入:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/task http://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 更新服务解析状态 (解析完成) } } }
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句