Exception handling for Spring 3.2 “@Scheduled” annotation

后端 未结 3 1708
野性不改
野性不改 2020-12-17 14:19

How to customize the exception handling for @Scheduled annotation from spring ?

I have Cron jobs which will be triggered in the server (Tomcat 6) and when any except

3条回答
  •  失恋的感觉
    2020-12-17 14:49

    Why not wrap your business logic and do a simple try catch in your @schedule method. Then you can log or take whatever action is necessary for failure cases.

    @Scheduled(cron = "${schedulerRate}")
    public void scheduledJob() {
        try {
            businessLogicService.doBusinessLogic();
        } catch (Exception e) {
            log.error(e);
        }
    }
    

提交回复
热议问题