美文网首页
定时任务

定时任务

作者: 无花无酒_3cd3 | 来源:发表于2020-07-13 20:41 被阅读0次

启动页

package com.yunda.demo2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;


@EnableScheduling  //开启定时任务
@EnableAsync  //开启异步
@SpringBootApplication
public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }

}

定时任务注解

package com.yunda.demo2.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class TaskC {
//秒 ,分 ,时 ,日 ,月  ,周
    @Scheduled(cron = "0 * * * * MON-SAT")  //定时任务注解,整分钟
@Scheduled(cron = "0,1,2,3 * * * * MON-SAT")  //定时任务注解,整分钟  逗号是枚举
@Scheduled(cron = "0-3 * * * * MON-SAT")  //定时任务注解,整分钟   -代表区间
@Scheduled(cron = "0/3 * * * * MON-SAT")  //定时任务注解,整分钟    /代表步长 ,每3秒执行一次
    public  void hello(){
        System.out.println("我啊是你的");
    };
}

异步

package com.yunda.demo2.task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class Taskwang {

    @Async   //异步注解
    public void hello(){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("王胜波ceLLL");
    }
}

A9EDD176-63C3-40c0-811A-C7C78BE72C4F.png

相关文章

  • 2019-07-31定时任务

    定时任务 定时任务实现方法 系统默认定时任务 用户自定义设置定时任务 定时任务配置文件 定时任务启动 定时任务样例...

  • 分布式定时调度-xxl-job

    一、定时任务概述 1.1 定时任务认识 1.1.1 什么是定时任务 定时任务是按照指定时间周期运行任务。使用场景为...

  • day 22 操作系统定时任务

    系统定时任务概念==生活中闹钟 系统定时任务实现方法: 实现定时任务配置: 定时任务如何进行设置 定时任务编写常见...

  • 7月30日 定时任务

    定时任务 代替人自动完成一些任务 定时任务实现的方法 定时任务软件:cronie定时任务软件:atd --- 设...

  • SpringBoot 定时任务

    1.如何定时任务 1.1 开启定时任务 1.2 @Scheduled(预定的)选择要定时执行的任务 == 定时在前...

  • crontab 定时任务

    查看当前用户的定时任务列表 创建(编辑)定时任务列表 定时任务格式 删除定时任务 注意 一定要设置crontab的...

  • 2019-10-14 定时任务方案

    定时任务方案 定时任务实现

  • Linux定时任务Crontab

    定时任务服务提供crontab命令来设定任务 定时任务命令: 定时任务服务提供crontab命令来设定任务 cro...

  • Android中 Handler延时 定时任务

    1.延时 2.定时任务,间隔固定时间执行某项任务 3.定时任务,间隔固定时间执行某项操作后关闭定时任务 参考:ht...

  • crondtab 定时任务

    编辑定时任务 crontab -e 查看定时任务 crontab -l 删除定时任务 crontab -r 如:*...

网友评论

      本文标题:定时任务

      本文链接:https://www.haomeiwen.com/subject/xhvzcktx.html