zoukankan      html  css  js  c++  java
  • spring+task配置

    1.spring+task文件配置

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xmlns:task="http://www.springframework.org/schema/task"
     5     xmlns:context="http://www.springframework.org/schema/context"
     6     xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd
     7         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
     8         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
     9 
    10 
    11     <task:annotation-driven/>
    12     <context:component-scan base-package="com.task"/>
    13 </beans>
    View Code

    2.业务类

     1 package com.task;
     2 
     3 import org.springframework.scheduling.annotation.Scheduled;
     4 import org.springframework.stereotype.Component;
     5 
     6 @Component
     7 public class TestScheduled {
     8 
     9      @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次  
    10     public void test(){
    11         for(long i=0;i<1000000000000000000l;i++){
    12             System.out.print((char)i);
    13             if(i%15==0){
    14                 System.out.println();
    15             }
    16         }
    17     }
    18 }
    View Code

    启动程序就开始跑了

  • 相关阅读:
    python---模块与包
    python---迭代器与生成器
    python---装饰器
    Python---函数
    Python---文件操作
    Python---数据类型
    浅谈UBUNTU
    java 键盘输入多种方法
    动态规划解最长公共子序列问题
    线段树
  • 原文地址:https://www.cnblogs.com/javaweb2/p/6254039.html
Copyright © 2011-2022 走看看