2
我想我从文档中得到了这个错误。GPars:等待演员完成
我有两个actor,XMLActor和HttpActor。 XMLActor读取xmlFiles,然后发送消息给HTTPActor进行处理。 XMLActor将比HttpActor更快完成。
我的主类调用两个actor的join。我期待主线程只会在两个演员完成后才会终止。但是,实际发生的情况是,只要所有消息都由XMLActor处理,系统就会终止并且很多消息不会被HttpActor处理。
我可以使用一些锁存器甚至AtomicInteger等待所有消息被消耗,但我想知道是否有一个更优雅的方式。
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)
}
你是对的,发生了什么事是HTTPActor这是默默地杀死进程异常。花了我一段时间才弄明白,因为脚本在后台运行并将输出发送到/ dev/null:D – 2013-02-22 16:02:13
有一个问题,是否需要调用stop?我遇到了另一个问题(OOM错误),我想知道这是否是由于我从未停止过演员的事实,并且我留下了几十万名活跃演员在内存中 – 2013-02-22 16:03:42