akka 入门
http://blog.csdn.net/thkhxm/article/details/40182835
1.首先安装akka的相关包-- http://akka.io/downloads/
2.导入依赖包,有几个是必须的。在刚开始win环境的eclipse下,卡住了很久- -。 就是因为少了一些包。。。。建议初学者可以跟我一样导入以下的依赖包。
akka-actor_2.11-2.3.6.jar
scala-library-2.11.2.jar
akka-remote_2.11-2.3.6.jar
config-1.2.1.jar
akka-slf4j_2.11-2.3.6.jar
接着就是简单的一个demo
- public class Actor01 extends UntypedActor {
- @Override
- public void onReceive(Object arg0) throws Exception {
- if(arg0 instanceof String)
- System.err.println("1-------------->"+arg0);
- }
- }
- import akka.actor.UntypedActor;
- public class Actor02 extends UntypedActor {
- @Override
- public void onReceive(Object arg0) throws Exception {
- if(arg0 instanceof String)
- System.err.println("2-------------->"+arg0);
- }
- }
- import akka.actor.ActorRef;
- import akka.actor.ActorSystem;
- import akka.actor.Props;
- public class DemoMain {
- public static void main(String[] args) {
- ActorSystem system = ActorSystem.create("demo1");
- ActorRef actor1 = system.actorOf(Props.create(Actor01.class));
- ActorRef actor2 = system.actorOf(Props.create(Actor02.class));
- actor1.tell("hello akka!!", actor2);
- system.shutdown();//
- }
- }