在這裏,我創建的路由器與SmallestMailboxRouter阿卡路由器具有多個行動者無法接收消息正確
ActorRef actorRouter = this?.getContext()?.actorOf(new Props(RuleStandardActor.class).withRouter(new SmallestMailboxRouter(38)),"standardActorRouter")
現在,在for循環我創建38名演員
for(int i=0;i <38;i++) {
ruleStandardActorRouter?.tell(new StandardActorMessage(standard: standard, responseVO: responseVO, report: report), getSelf());
}
每個演員將處理邏輯,並返回分數和消息。我通過重寫接收方法並將它們添加到列表中來接收消息
如果我多次運行該程序,我會得到不同的分數。但它應該總是返回相同的分數,因爲我給予相同的輸入。
if (message instanceof StandardActorResponse) {
StandardActorResponse standardActorResponse = message
standardActorResponseList?.add(standardActorResponse)
}
這裏standardActorResponse包含消息和得分。如果我通過使用for循環而不是akka框架來使用相同的邏輯,我正在接受conisstant結果。但在阿卡隨機獲得不同的結果。例如我有一些像loginexistence和navigationexistence和alertsexistence規則的規則。我已經給這些規則提供了一個html源代碼來檢查html源代碼是否有登錄,警報,導航鏈接。有時候我登錄不存在,有時導航不存在,有時使用akka路由器和演員警報不存在。但如果我使用for循環,我總是得到相同的結果
任何人都可以幫助我找到問題。我正在使用akka 2.1.4
Hi @koozz。謝謝。我已經包含Thread.sleep(100);在調用tell方法後進入for循環。我在閱讀你的回覆之前就已經包含了這個,並且獲得了成功,但我不知道它是如何工作的。在閱讀你的回覆後我明白了..謝謝澄清 – Jagadeesh