I have a Spring-Boot application with a bean that runs a scheduled task at 1 minute intervals, and this bean has a method @PreDestroy.
@PreDestroy
Is there a solution to the task that is currently being completed, to complete, or at least give some time to complete, before the life cycle reaches the phase before destruction?
You need update settings ThreadPoolTaskScheduler. Set true to waitForJobsToCompleteOnShutdown(method setWaitForTasksToCompleteOnShutdown).
ThreadPoolTaskScheduler
waitForJobsToCompleteOnShutdown
setWaitForTasksToCompleteOnShutdown
From the documentation:
, , . "false", , . "true", .
@Matej . , ,
@Bean public ThreadPoolTaskScheduler setSchedulerToWait(ThreadPoolTaskScheduler threadPoolTaskScheduler){ threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true); return threadPoolTaskScheduler; }
Spring Boot 2.1.0, :
@Bean TaskSchedulerCustomizer taskSchedulerCustomizer() { return taskScheduler -> { taskScheduler.setAwaitTerminationSeconds(60); taskScheduler.setWaitForTasksToCompleteOnShutdown(true); }; }
TaskSchedulerCustomizer ThreadPoolTaskScheduler
TaskSchedulerCustomizer
:
Source: https://habr.com/ru/post/1675832/More articles:docker: 'stack' не является командой докера - dockerSubscribe to an HTML element observed in Angular 2 - htmlIntegration of VS Code extensions in Monaco editor - node.jsAlexa Flask Ask Yes / No Answer - pythonHow to avoid reinstalling a component if it is necessary to update a URI (for example, a filter button)? - javascriptPSQLException: column name clazz_ was not found in this ResultSet - spring-data* ngTo reset all form values when adding a new input element - angularHow can I remove PyTorch? - pythonInsert image into Google Sheets cell using Google APIs - javascriptJava vs Scala Using a functional interface - javaAll Articles