Akka 配置Dispatcher(一)
来源:互联网 发布:ubuntu hdmi电视 编辑:程序博客网 时间:2024/06/05 02:54
Akka 配置Dispatcher(一)
akka默认加载classpath下application.conf配置文件,在application.conf配置文件中配置Dispatcher
如下定义一个application.conf配置文件,
akka { loglevel = INFO}my-dispatcher { # Dispatcher is the name of the event-based dispatcher type = Dispatcher # What kind of ExecutionService to use executor = "fork-join-executor" # Configuration for the fork join pool fork-join-executor { # Min number of threads to cap factor-based parallelism number to parallelism-min = 2 # Parallelism (threads) . . . ceil(available processors * factor) parallelism-factor = 2.0 # Max number of threads to cap factor-based parallelism number to parallelism-max = 10 } # Throughput defines the maximum number of messages to be # processed per actor before the thread jumps to the next actor. # Set to 1 for as fair as possible. throughput = 100}
如何使用这个Dispatcher的配置?
首先定义一个Actor,如下,
package com.usoft6;import akka.actor.UntypedActor;/** * Created by liyanxin on 2015/1/12. */public class MyActor extends UntypedActor { private int x; private int y; public MyActor(int x, int y) { this.x = x; this.y = y; } @Override public void onReceive(Object message) throws Exception { System.out.println("接收到的消息=" + message); int result = x + y; this.getSender().tell(result, this.getSelf()); this.getContext().stop(this.getSelf()); }}
DispatcherDemo1.java
package com.usoft6;import akka.actor.ActorRef;import akka.actor.ActorSystem;import akka.actor.Props;import akka.pattern.Patterns;import akka.util.Timeout;import scala.concurrent.Await;import scala.concurrent.Future;import scala.concurrent.duration.Duration;/** * Created by liyanxin on 2015/1/13. */public class DispatcherDemo1 { public static void main(String args[]) throws Exception { ActorSystem system = ActorSystem.create("myActorSystem"); ActorRef myActor = system.actorOf(Props.create(MyActor.class, 54, 65). withDispatcher("my-dispatcher"), "myactor"); Timeout timeout = new Timeout(Duration.create(5, "seconds")); Future<Object> future = Patterns.ask(myActor, "are you ready?", timeout); // This will cause the current thread to block and wait for the UntypedActor to ‘complete’ // the Future with it’s reply. // 在这里会阻塞到 Await.result 方法上,但这会导致性能的损失。 Integer result = (Integer) Await.result(future, timeout.duration()); System.out.println(result); }}这块代码指定Dispatcher的配置, ActorRef myActor = system.actorOf(Props.create(MyActor.class, 54, 65). withDispatcher("my-dispatcher"), "myactor");
=============END=============
阅读全文
0 0
- Akka 配置Dispatcher(一)
- 学习akka之dispatcher
- Akka 实践(一)Akka基础
- Akka 实践(一)Akka基础
- Akka 初探(一)
- Akka 【七】 Dispatcher and Router
- akka 之 Dispatcher学习笔记
- AKKA-源码-dispatcher的构建过程
- AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)
- 使用Akka构建集群(一)
- 使用Akka构建集群(一)
- Scala---Akka Actor (一)tutorial-1
- Scala---Akka Actor(一)tutorial-2
- Akka学习笔记(七):配置
- Akka学习笔记(七):配置
- SpringMVC—Dispatcher配置
- Akka 【一】 HelloWorld
- Akka边学边写(一)
- C语言结构体内存对齐的问题
- STM32用IAR调试出现Error[Pe020]: identifier "FILE" is undefined 解决方法
- urllib
- Mysql JDBC 的简单操作
- Vue-Webpack简单脚手架搭建
- Akka 配置Dispatcher(一)
- VS2017整合proc(C++篇)
- Centos7 离线安装mysql5.7并设置开机自启
- 散文阅读书
- 常用激活函数比较
- Hdu2063-过山车-【二分法】
- 继承性的两个特殊问题
- JVM的内存区域划分
- DHCP动态主机配置协议