Search code examples
javamultithreadingspringbackground-process

How to create background process in spring webapp?


I want to run background process in parallel with my spring-mvc web-application. I need a way to start in automatically on context loading. Background process is a class that implements Runnable. Is spring-mvc has some facilities for that?


Solution

  • Spring has a comprehensive task execution framework. See the relevant part of the docs.

    I suggest having a Spring bean in your context, which, when initialized, submits your background Runnable to a SimpleAsyncTaskExecutor bean. That's the simplest approach, which you can make more complex and capable as you see fit.