Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run background process in spring mvc framework

I have a web-application (using spring mvc framework). It makes the following:

  1. Users upload a file to server.
  2. Go to success page immediately.
  3. Run a background process with that file.

So, how I can do this with spring mvc framework? Thank You in Advance!

like image 627
chicky Avatar asked Jan 21 '15 03:01

chicky


2 Answers

Use asynchronous marked method. You got example here:

https://spring.io/guides/gs/async-method/

and docs:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling

like image 140
mariubog Avatar answered Oct 19 '22 06:10

mariubog


You can use JobRunr (https://github.com/jobrunr/jobrunr) in your controller. You should add Maven dependency jobrunr-spring-boot-starter. Then you can run your code on separate thread:

@Inject
private JobScheduler jobScheduler;
...
jobScheduler.enqueue(() -> someJobService.executeSampleJob());

For more details you can check: https://www.baeldung.com/java-jobrunr-spring

like image 36
nikolai.serdiuk Avatar answered Oct 19 '22 07:10

nikolai.serdiuk