zoukankan      html  css  js  c++  java
  • Spring Task定时任务Scheduled

    Spring的任务调度,采用注解的形式

    Spring中@Scheduled的用法。

    spring的配置文件如下,先扫描到任务的类,打开spirng任务的标签

    
    <beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:task="http://www.springframework.org/schema/task"   
        --------------------
        xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">  
    <!-- 扫描controller -->
    <context:component-scan base-package="com.springmvc.controller" />
    <task:annotation-driven/>
    

    Spring的任务类HelloJobController

    package com.springmvc.controller;
    
    import java.util.Date;
    
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    
    @Component
    public class HelloJobController {
    
    	@Scheduled(cron = "*/5 * * * * ?")
    	//@Scheduled(fixedDelay = 5000)
    	public void demoServiceMethod() {
    		System.out.println("Method executed at every 5 seconds. Current time is :: " + (new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
    		
    	}
    
    }
    
    

    运行结果

    scheduling

    task-scheduling-simplifications-in-spring-3-0

  • 相关阅读:
    [SDOI2016]排列计数
    Broken robot
    环路运输
    naptime
    Accumulation Degree
    选课
    没有上司的舞会
    金字塔
    Polygon
    石子合并
  • 原文地址:https://www.cnblogs.com/tonyY/p/4769171.html
Copyright © 2011-2022 走看看