Groovy GPAR:等待演员完成
我想我从医生那里搞错了 我有两个演员,XMLActor和HttpActor。XMLActor读取xmlFiles,然后向HTTPActor发送一条消息进行处理。XMLActor将比HttpActor更快完成 我的主要课程要求两位演员都加入。我希望主线程只有在两个角色都完成后才会终止。但是,实际发生的情况是,只要XMLActor处理完所有消息,系统就会终止,并且HttpActor不会处理很多消息 我可以使用一些闩锁,甚至原子整数来等待所有消息被消费,但我想知道是否有一种更优雅的方式Groovy GPAR:等待演员完成,groovy,gpars,Groovy,Gpars,我想我从医生那里搞错了 我有两个演员,XMLActor和HttpActor。XMLActor读取xmlFiles,然后向HTTPActor发送一条消息进行处理。XMLActor将比HttpActor更快完成 我的主要课程要求两位演员都加入。我希望主线程只有在两个角色都完成后才会终止。但是,实际发生的情况是,只要XMLActor处理完所有消息,系统就会终止,并且HttpActor不会处理很多消息 我可以使用一些闩锁,甚至原子整数来等待所有消息被消费,但我想知道是否有一种更优雅的方式 final H
final HttpActor httpActor = new HttpActor().start()
final XMLActor xmlActor = new XMLActor(httpActor:httpActor).start()
Actors.actor {
file.eachLine { line ->
def chunks = line.split(",")
def id = chunks[0].replaceAll("\\\"","").trim()
def name = chunks[1].replaceAll("\\\"","").trim()
xmlActor << new FileToRead(basePath:args[1],id:id,name:name, fileCounter:counter)
}
}
[httpActor, xmlActor]*.join()
//inside xmlActor
countries.each { country ->
httpActor << new AlbumPriceMessage(id:message.id, country:country)
}
final-HttpActor-HttpActor=new-HttpActor().start()
final XMLActor XMLActor=新的XMLActor(httpActor:httpActor).start()
演员,演员{
file.eachLine{line->
def chunks=line.split(“,”)
def id=chunks[0]。replaceAll(“\\\”,“”)。trim()
def name=chunks[1]。replaceAll(“\\\”,“”)。trim()
xmlActor
httpActorjoin()方法肯定会等待两个参与者完成。我不知道如何阻止这两个参与者,因此无法对此发表评论。您是否发送了此类有毒消息?或者对参与者调用stop()
例如,以下案例模拟将正确停止:
import groovyx.gpars.actor.*;
def httpActor = Actors.staticMessageHandler {
println "Http actor processing " + it
}
def xmlActor = Actors.staticMessageHandler {
println "XML Actor processing " + it
httpActor << it
}
xmlActor.metaClass.afterStop = {
httpActor.stop()
}
100.times {
xmlActor << "File$it"
}
xmlActor.stop()
[xmlActor, httpActor]*.join()
println "done"
导入groovyx.gpars.actor.*;
def httpActor=Actors.staticMessageHandler{
println“Http参与者处理”+它
}
def xmlActor=Actors.staticMessageHandler{
println“XML参与者处理”+它
httpActor您是对的,httpActor中发生的异常正在悄悄地终止进程。由于脚本在后台运行并将输出发送到/dev/null:DOne,所以我花了一段时间才弄明白,是否必须调用stop?我遇到了另一个问题(OOM错误),我想知道这是否是因为我从未阻止过演员们,而我的记忆中留下了几十万活跃的演员