Grails异步引导 [英] grails async bootstrap
本文介绍了Grails异步引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在grails bootstrap类中异步使用服务?
我想在grails-2.0.4和grails-executor-plugin中执行以下操作,但只会显示第一条日志消息:
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!
推荐答案
删除 runAsync
关闭 - 它不适合它。您可以在这里针对不同环境使用像 production 和
development
这样的闭包:
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
}
}
}
这篇关于Grails异步引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文