81,122
社区成员




<?xml version="1.0" encoding="utf-8"?>
<beans default-init-method="init" default-destroy-method="destroy"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<!-- Enables the Spring Task @Scheduled programming model -->
<task:executor id="executor" pool-size="5" />
<task:scheduler id="scheduler" pool-size="10" />
<task:annotation-driven executor="executor" scheduler="scheduler" />
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="com.yundaex.gpd.task.impl"/>
</beans>
@Component
public class DynamicReportTaskImpl implements DynamicReportTask {
private Logger logger = Logger.getLogger(DynamicReportTask.class);
@Autowired
private DynamicStockService dynamicStockService;
/*
* CRON表达式 含义
" 0 0 12 * * ?" 每天中午十二点触发
" 0 15 10 ? * *" 每天早上10:15触发
" 0 15 10 * * ?" 每天早上10:15触发
" 0 15 10 * * ? *" 每天早上10:15触发
" 0 15 10 * * ? 2005" 2005年的每天早上10:15触发
" 0 * 14 * * ?" 每天从下午2点开始到2点59分每分钟一次触发
" 0 0/5 14 * * ?" 每天从下午2点开始到2:55分结束每5分钟一次触发
" 0 0/5 14,18 * * ?" 每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发
" 0 0-5 14 * * ?" 每天14:00至14:05每分钟一次触发
" 0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发
" 0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发
* */
// @Scheduled(cron = "0/30 * * * * ? ") //每10秒执行一次
@Scheduled(cron = "0 59 23 ? * *") //每天23:59分执行生成动态报表操作
public void generateDynamicReport() {
logger.info("库存动态报表任务启动!");
DynamicStock dynamicStock = new DynamicStock();
// 获得结果集合,依次set进去 new DynamicDetailStock()
// TODO 创建今天的任务批次
// TODO 创建该次生成报表结果集明细
try {
dynamicStockService.create(dynamicStock);
} catch (Exception e) {
e.printStackTrace();
}
logger.info("库存动态报表任务结束!");
}
}
package com.founder.ec.web.TimerTask;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;//定时器类
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/****
*
* 类描述: 定时每天几点钟执行一次
*
* @author: Janc
* @time:2013-9-28
*/
public class SysContextListener_Return implements ServletContextListener {
private Timer timer = null;// 重写contextInitialized
public void contextInitialized(ServletContextEvent event) {
// 在这里初始化监听器,在tomcat启动的时候监听器启动,可以在这里实现定时器功能
timer = new Timer(true);
// 添加日志,可在tomcat日志中查看到
event.getServletContext().log("定时器已启动");
//指定任务在晚上23点25分执行:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 50);
calendar.set(Calendar.SECOND, 00);
Date time = calendar.getTime();
timer = new Timer();
timer.schedule(new Times_Return_Order(), time);
Calendar calendar1 = Calendar.getInstance();
calendar1.set(Calendar.HOUR_OF_DAY, 23);
calendar1.set(Calendar.MINUTE, 55);
calendar1.set(Calendar.SECOND, 00);
Date time1 = calendar1.getTime();
timer.schedule(new Times_Result_Xml(), time1);
}
// 重写contextDestroyed
public void contextDestroyed(ServletContextEvent event) {
// 在这里关闭监听器,所以在这里销毁定时器。 timer.cancel();
event.getServletContext().log("定时器销毁");
}
}
package com.founder.ec.web.TimerTask;
import java.io.IOException;
import java.util.TimerTask;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.springframework.stereotype.Controller;
/***
* 定时器,定时每天几点钟执行一次
*
* @author Janc
*
*/
@Controller
public class Times_Return_Order extends TimerTask {
public void run() {
// 此处编写任务内容,定时器暂时不执行内容,需要时开启
System.out.println("this is Timer action");
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(
"http://localhost:8080/ec-orderdc/page/returnOrder/acceptData");
try {
client.executeMethod(method);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (method.getStatusCode() == HttpStatus.SC_OK) {
}
method.releaseConnection();
}
}