@ Override public void configureTasks ( ScheduledTaskRegistrar taskRegistrar ) { BugsnagScheduledTaskExceptionHandler bugsnagErrorHandler = new BugsnagScheduledTaskExceptionHandler ( bugsnag ) ; // Decision process for finding a TaskScheduler, in order of preference: // // 1. use the scheduler from the task registrar // 2. search for a TaskScheduler bean, by type, then by name // 3. search for a ScheduledExecutorService bean by type, then by name, // and wrap it in a TaskScheduler // 4. create our own TaskScheduler TaskScheduler registrarScheduler = taskRegistrar . getScheduler ( ) ; TaskScheduler taskScheduler = registrarScheduler != null ? registrarScheduler : beanLocator . resolveTaskScheduler ( ) ; if ( taskScheduler != null ) { configureExistingTaskScheduler ( taskScheduler , bugsnagErrorHandler ) ; } else { ScheduledExecutorService executorService = beanLocator . resolveScheduledExecutorService ( ) ; taskScheduler = createNewTaskScheduler ( executorService , bugsnagErrorHandler ) ; taskRegistrar . setScheduler ( taskScheduler ) ; } }
Add bugsnag error handling to a task scheduler