Search code examples
javaspringbackground-process

Background job support in Spring


I am looking for support from Spring to execute background jobs. I want to trigger the jobs from my application and run in the background without hampering the execution of the application. How can I do it?


Solution

  • See link from hasnae above. In Java Config you can do something like:

    @EnableScheduling
    @Configuration
    public class BackgroundTaskScheduler {
    
        @Autowired
        private BackgroundTaskBean backgroundTaskBean;
    
        @Scheduled(cron = "${property.cronStatement}")
        public void backgroundTaskOne() {
            backgroundTaskBean.runTask();
        }
    }