spring-task 设置10秒执行一次,怎么每次都执行很多次

每次都执行很多次

import java.text.SimpleDateFormat;
import java.util.Date;

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

@Component
public class CsTask {

    @Scheduled(cron = "0/10 * * * * ?")
    public void taskCron(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
        String sdf = simpleDateFormat.format(new Date());
        System.out.println("cron: " + sdf);
    }
    
}

微信图片_20200610214113.png

阅读 3k
1 个回答

直接复制粘贴你的代码

cron: 2020-06-10 22:20:00
cron: 2020-06-10 22:20:10
cron: 2020-06-10 22:20:20
cron: 2020-06-10 22:20:30
cron: 2020-06-10 22:20:40
cron: 2020-06-10 22:20:50
cron: 2020-06-10 22:21:00

重新build/重启/重写应该可解

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题