Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 970 Bytes

executor_service.md

File metadata and controls

28 lines (22 loc) · 970 Bytes

Working with Executor Service

When you want to execute asynchronous code you have to use ExecutorService provided by Grails Executor Plugin. This brings some constraints for what can be run inside the asynchronous task.

Working with any entity

You cannot work with the entity reference directly, you have to store it's id and get it by that id inside the task closure

Long id = dataModel.getId()

executorService.submit {
    DataModel theDataModel = DataModel.get(id)
    // do something with data model
}

Working with objects related to request and response

In similar way you have to store all the information from the request, params, headers or response needed inside the task closure

String description = params.description
executorService.submit {
    // do something with description
}