亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

java - AKKA actor創建錯誤

瀏覽:104日期:2024-02-10 18:47:58

問題描述

class Master(val host: String, val port: Int) extends Actor 第一種寫法val masterActor=new Master(host, port)val master = actorSystem.actorOf(Props(masterActor), 'Master')

Exception in thread 'main' akka.actor.ActorInitializationException: You cannot create an instance of [test.rpc.Master] explicitly using the constructor (new). You have to use one of the ’actorOf’ factory methods to create a new actor. See the documentation.

at akka.actor.ActorInitializationException$.apply(Actor.scala:167)at akka.actor.Actor$class.$init$(Actor.scala:423)at test.rpc.Master.<init>(Master.scala:13)at test.rpc.Master$.main(Master.scala:106)at test.rpc.Master.main(Master.scala)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

You cannot create an instance of [test.rpc.Master] explicitly using the constructor (new). You have to use one of the ’actorOf’ factory methods to create a new actor.

錯誤的代碼是:val masterActor=new Master(host, port) 這行代碼在執行的時候出錯了,拋出了異常

第二中寫法這種寫法就沒有錯誤:val master = actorSystem.actorOf(Props(new Master(host, port)), 'Master')

第二種寫法中也會是首先執行new Master(host,port),為什么第二種寫法中就沒有拋出異常呢???

以上兩種寫法都是會首先執行new Master的。

已知:actor的創建需要有繼承體系,實例是不能直接使用new 來創建的。而是使用系統的actorOf方法來創建,注意Actor之間有層次關系(和人類社會一樣)。

問題: 第二中寫法也是直接new了actor 就沒報錯,原因是什么那

main方法主要代碼:

def main(args: Array[String]): Unit = { val host = args(0) val port = args(1).toInt println(host) println(port) val config = ...... val actorSystem = ActorSystem('MasterSystem', config)//第一中方式,自己new,結果就是運行不起來,直接報錯 val masterActor= new Master(host, port) val master = actorSystem.actorOf(Props(masterActor), 'Master') //第二種方式, 這行代碼中也有new Master,但是程序可以正常運行,不會出錯val master = actorSystem.actorOf(Props(new Master(host, port)), 'Master') actorSystem.awaitTermination() }

問題解答

回答1:

第二種哪里是直接new了,不是actorSystem的工廠方法創建的么?把你的main方法所有代碼貼出來

標簽: java
相關文章:
主站蜘蛛池模板: 久久久久久尹人网香蕉 | 欧美激情片网站 | 国产美女激情视频无打码 | 久久91久久91精品免费观看 | 在线观看成年人免费视频 | 成人免费小视频 | 国产黄网站 | 99久久免费精品国产免费 | 国产成人亚洲精品蜜芽影院 | 91香蕉嫩草| 欧美xxxx性疯狂bbbb | 国产精品国产三级国产专区5o | 欧美一级毛片图 | 特黄特黄 | 久久久久国产 | 日韩免费观看的一级毛片 | 日韩精品第一区 | 久久ri精品高清一区二区三区 | 欧美一级黄色带 | 国产黄a三级三级三级 | xxxxx网| 欧美aaaa黄色一级毛片 | 一区视频在线播放 | 成人免费午夜性视频 | 亚洲精品毛片久久久久久久 | 日本成人黄色片 | 久久精品免费一区二区三区 | 91视频网址 | 中文字幕有码在线视频 | 小明看片成人永久在线观看 | 未满十八18周岁禁止免费国产 | 乱爱性全过程免费视频 | 91激情视频| 亚洲欧美二区三区久本道 | 91亚洲视频在线观看 | 91精东| 欧美大片va欧美在线播放 | 日本高清不卡免费 | 欧美情趣视频 | 亚洲 国产 路线1路线2路线 | 最新91视频|