午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

java - AKKA actor創(chuàng)建錯(cuò)誤

瀏覽:242日期: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.

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

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

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

以上兩種寫法都是會(huì)首先執(zhí)行new Master的。

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

問題: 第二中寫法也是直接new了actor 就沒報(bào)錯(cuò),原因是什么那

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,結(jié)果就是運(yùn)行不起來,直接報(bào)錯(cuò) val masterActor= new Master(host, port) val master = actorSystem.actorOf(Props(masterActor), 'Master') //第二種方式, 這行代碼中也有new Master,但是程序可以正常運(yùn)行,不會(huì)出錯(cuò)val master = actorSystem.actorOf(Props(new Master(host, port)), 'Master') actorSystem.awaitTermination() }

問題解答

回答1:

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

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 伊人久久一区二区 | 秋霞欧美网 | 中文字幕在线观看第二页 | www日韩精品 | 国产成人传媒 | 欧美日韩在线播放视频 | 91激情视频在线观看 | av国产免费| 国产精品高潮视频 | 青青免费在线视频 | 三区四区在线观看 | 中文字幕在线观看日韩 | 九九视频在线播放 | 成人国产在线 | 激情五月色婷婷 | 久草午夜| 国产精品一二三四区 | 欧美一级二级三级视频 | 亚洲欧美日韩久久 | 国产特黄一级片 | 日本在线视频一区二区 | 国产精品一二三四五区 | 免费看久久 | 裸体武打性艳史 | 青青草黄色| 一色综合 | 超碰狠狠干 | 日日操影院| 美女黄色一级视频 | 四虎影院永久地址 | 黄页网站在线看 | 成人高清在线观看 | 77久久 | 国产裸体永久免费无遮挡 | 欧美日本综合 | 国产成年人在线观看 | 国产精品久久久久久久久免费 | xxxx日韩| 欧美久久久久久久 | av在线超碰 | 国产99热|