SpringTask

来源:互联网 发布:c 执行sql语句代码 编辑:程序博客网 时间:2024/04/29 00:47

一、workerContext.xml 配置

1、在xmlns中添加

    xmlns:task="http://www.springframework.org/schema/task"

2、在xsi:schemaLocation中添加内容

    http://www.springframework.org/schema/task     http://www.springframework.org/schema/task/spring-task-3.0.xsd
3、添加任务

<task:scheduled-tasks>           <task:scheduled ref="scheduleTaskWork" method="task" cron="0/30 * * * * ?"/>    </task:scheduled-tasks>

二、work类

package com.beichenyashi.apps.mgr.printagent.worker;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import com.beichenyashi.apps.mgr.printagent.config.ServerConfig;import com.beichenyashi.apps.mgr.printagent.service.IScheduleTaskService;/** * agent轮询任务 * @author jiangxingqi * */@Component("scheduleTaskWork")public class ScheduleTaskWork {/**agent轮询执行获取手机端需要打印的任务 然后在本地进行打印 的service 服务*/@Autowiredprivate IScheduleTaskService scheduleTaskService;/**服务器的信息  */@Autowiredprivate ServerConfig server;/** * 轮询 手机端打印请求,并获取最早打印请求的检测编号,完成打印 */public void task() {scheduleTaskService.getBlockedPrintTask(server.getIp(), server.getPort(), server.getContextPath());}}




0 0