How to run a thread in background using grails 2.3.11

172 views Asked by At

Trying to write a exportservice run in background. logic :

1: when user click on export button

2: that export feature will run in backgound. and user will continue other work.. no need to wait until export feature complete

I am using grails 2.3.11

2

There are 2 answers

0
light_303 On

you can use the @DelegateAsync keyword on your service methods to get them executed by the global executor service.

The documentation also describes how to handle result events : https://grails.github.io/grails-doc/latest/guide/async.html

0
defectus On

You know that spawning arbitrary threads and leaving them on their own can be dangerous? You can end up with dozens of export threads running and no way of controlling them.

Better ways of doing this include using quartz scheduler and run export jobs whenever you need to, have an async (message driven?) worker apps/threads and some web containers provide built-in worker services.

Simply put, there's plenty of ways of doing this securely and in a controlled manner.