【发布时间】:2014-06-06 20:39:48
【问题描述】:
我想要一个应用程序来监听 TCP 套接字连接并对其做出反应。为此,我需要在启动时启动一个后台线程——我可以在 BootStrap.groovy 中做到这一点。
对于后台线程,我下载了executor plugin。
代码如下所示:
class BootStrap {
def myService
def init = { servletContext ->
log.info("Bootstrapping")
development {
log.info("Doing myService async ")
myService.doSomething()
}
}
class MyService {
def doSomething() {
runAsync {
println "Running!"
}
}
}
}
此代码是从another thread 这里的 SO 复制粘贴。
我收到此错误:
| Error 2014-06-06 22:30:37,317 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Cannot invoke method doSomething() on null object
Message: Cannot invoke method doSomething() on null object
Line | Method
->> 14 | doCall in BootStrap$_closure1_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
似乎未填充 myService 对象。我需要编辑一些配置吗?
编辑:尝试使用 executorService,但这也无济于事。
| Error 2014-06-07 00:06:36,099 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Cannot invoke method doSomething() on null object
Message: Cannot invoke method doSomething() on null object
Line | Method
->> 14 | doCall in BootStrap$_closure1_closure2
【问题讨论】: