grails async bootstrap

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

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         }     } } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!