背景
在使用scheduledExecutorService.scheduleAtFixedRate
()
时发现定时任务不知道在什么时候就停了,因为有了解到scheduledExecutorService
会因为出现异常而停止定时任务,所以我特地加了try/catch
捕获异常,代码大致如下:
scheduledExecutorService.scheduleAtFixedRate(() -> {
try {
service.backupData(1);
} catch (Exception e) {
System.out.println("This is Exception!");
log.error(e.getMessage());
System.out.println("=========================");
}, 1, 10, TimeUnit.SECONDS);
好奇怪= =于是又去仔细翻阅了官方文档里面的记录