0
点赞
收藏
分享

微信扫一扫

计蒜客:C10 第四部分:深度优先搜索基础 引爆炸弹

岛上码农 2024-06-11 阅读 7

1.1、JDK1.3 开始推出定时任务实现工具。

1.2、API
在这里插入图片描述

执行代码

    public static void main(String[] args) throws ParseException {
        Timer timer = new Timer();
        String str="2024-06-10 23:24:00";
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("定时任务执行");
                System.out.println("定时任务执行时间--》"+new Date());
            }
        },date);
    }
    public static void main(String[] args) throws ParseException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("定时任务执行");
                System.out.println("定时任务执行时间--》"+new Date());
            }
        },0,2000);
    }

在这里插入图片描述

//pom文件
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
spring:
  task:
    execution:
      thread-name-prefix: task_
      shutdown:
        await-termination: false
        await-termination-period: 10s
    scheduling:
      pool:
        size: 10
    @Scheduled(cron = "0/3 * * * * ? ")
    public void test1() {
        System.out.println("定时任务执行test1");
        System.out.println("定时任务执行时间--》"+new Date());
    }
    @Scheduled(cron = "0/3 * * * * ? ")
    public void test2() {
        System.out.println("定时任务执行test2");
        System.out.println("定时任务执行时间--》"+new Date());
    }
举报

相关推荐

0 条评论