问题
Is it possible to use a service asynchronously in the grails bootstrap class? I am trying to do the following in grails-2.0.4 and the grails-executor-plugin, but only the first log message appears:
class BootStrap {
def myService
def init = { servletContext ->
log.info("Bootstrapping")
runAsync {
log.info("Doing myService async ")
myService.doSomething()
}
}
There is no error message, just no output from the second log statement. Thanks a lot in advance!
回答1:
Remove runAsync
closure - it is not the right place for it. You can use closures like production
and development
here for different environments:
class BootStrap {
def myService
def init = { servletContext ->
log.info("Bootstrapping")
development {
log.info("Doing myService async ")
myService.doSomething()
}
}
class MyService {
def doSomething() {
runAsync {
// executed asynchronously
}
}
}
来源:https://stackoverflow.com/questions/11078503/grails-async-bootstrap