Use TaskScheduler from Spring to start/stop a task.
Task Scheduling programmatically with Spring Boot