Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Created May 29, 2017 12:24
Show Gist options
  • Save luismoramedina/ee175da332a992e82340606ec76d35f5 to your computer and use it in GitHub Desktop.
Save luismoramedina/ee175da332a992e82340606ec76d35f5 to your computer and use it in GitHub Desktop.
Background task in controller
@RequestMapping("/job/start")
public String start() throws ExecutionException, InterruptedException {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
try {
System.out.println("BGController.before");
Thread.sleep(10000);
System.out.println("BGController.after");
} catch (InterruptedException e) {
e.printStackTrace();
}
});
return "start";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment