我有以下的Groovy代码:Groovy的等待/通知
abstract class Actor extends Script {
synchronized void proceed() {
this.notify()
}
synchronized void pause() {
wait()
}
}
class MyActor extends Actor {
def run() {
println "hi"
pause()
println "hi again"
}
}
def theactor = new MyActor()
theactor.run()
theactor.proceed()
当我运行代码,我想要的代码输出“喜”和“喜试”。相反,它只停在“hi”处,并停留在pause()函数上。关于如何继续该计划的任何想法?
我正在做的是制作一个游戏的脚本NPC。当玩家与NPC互动时,我会触发继续功能。感谢链接到Gpars;我会研究它。 –
我会看看这一章[在演员](http://www.gpars.org/guide/guide/5.%20Actors.html)。不知道演员如何扩展到游戏可能需要的数千人以上?可能值得在邮件列表上询问(http://xircles.codehaus.org/lists/[email protected])? –
不错的答案tim :) –