How to create background process in spring webapp?

Vladimir picture Vladimir · Dec 21, 2009 · Viewed 28.5k times · Source

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?

Answer

skaffman picture skaffman · Dec 21, 2009

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.