任务调度

1.timer方式


public void timer() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 17); // 控制时
calendar.set(Calendar.MINUTE, 30); // 控制分
calendar.set(Calendar.SECOND, 0); // 控制秒


final Date time = calendar.getTime(); // 得出执行任务的时间
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
System.out.println("-------设定要指定任务--------"+time);
}
}, time, 12);// 这里设定将延时每天固定执行
}



 初始化(启动tomcat时任务调度)
 
public void init(FilterConfig fc) throws ServletException {
timer();
}


配置xml

  <filter>
    <filter-name>startFilter</filter-name>
    <filter-class>com.fh.filter.startFilter</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>startFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>



2.task方式

添加

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

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd


<!-- 任务调度 -->
<task:scheduled-tasks>   
        <task:scheduled ref="tradeService" method="insertOrUpdateFundList" cron="0 0 0/1 * * ?"/>    (0点开始,每一个小时执行一次)
        <task:scheduled ref="tradeService" method="uploadCustImageList" cron="0 0 3 * * ?"/>            (3点开始,每天一次)
</task:scheduled-tasks>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值