actor

Scala actors - worst practices? [closed]

风格不统一 提交于 2019-11-27 08:57:23
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 months ago . I feel a bit insecure about using actors in Scala. I have read documentation about how to do stuff, but I guess I would also need some DON'T rules in order to feel free to use them. I think I am afraid that I will use them in a wrong way, and I will not even notice it. Can

167 Scala Actor

佐手、 提交于 2019-11-27 07:23:45
Scala中的Actor能够实现并行编程的强大功能,它是基于事件模型的并发机制, Scala是运用消息(message)的发送、接收来实现多线程的。 使用Scala能够更容易地实现多线程应用的开发。 传统java并发编程与Scala Actor编程的区别 对于Java,我们都知道它的多线程实现需要对共享资源(变量、对象等)使用synchronized 关键字进行代码块同步、对象锁互斥等等。而且,常常一大块的try…catch语句块中加上wait方法、notify方法、notifyAll方法是让人很头疼的。 原因就在于Java中多数使用的是可变状态的对象资源,对这些资源进行共享来实现多线程编程的话,控制好资源竞争与防止对象状态被意外修改是非常重要的,而对象状态的不变性也是较难以保证的 。 而在Scala中,我们可以 通过复制不可变状态的资源(即对象,Scala中一切都是对象,连函数、方法也是)的一个副本,再基于Actor的消息发送、接收机制进行并行编程。 Actor方法执行顺序 1.首先调用start()方法启动Actor 2.调用start()方法后其act()方法会被执行 3.向Actor发送消息 发送消息的方式 来源: https://blog.csdn.net/qq_20042935/article/details/99546782

大数据学习day17------第三阶段-----scala05------1.Akka RPC通信案例改造和部署在多台机器上 2. 柯里化方法

假装没事ソ 提交于 2019-11-27 05:38:05
1.Akka RPC通信案例改造和部署在多台机器上 1.1 Akka RPC通信案例的改造(主要是把一些参数不写是) Master package com._51doit.akka.rpc import akka.actor.{Actor, ActorRef, ActorSystem, Props} import com.typesafe.config.ConfigFactory import scala.concurrent.duration._ import scala.collection.mutable // Actor编程模型进行通信,需要让其与AKKA发生点关系(此处实现Actor特质) class Master extends Actor { // 定义一个map,用来接收数据 val id2Worker = new mutable.HashMap[String, WorkerInfo]() // 在preStart中启动定时器,定期检查超超时的Worker,然后剔除 override def preStart(): Unit = { import context.dispatcher context.system.scheduler.schedule(0 millisecond, 10000 millisecond, self, CheckTimeOutWorker

How to implement actor model without Akka?

心已入冬 提交于 2019-11-27 01:46:30
问题 How to implement simple actors without Akka? I don't need high-performance for many (non-fixed count) actor instances, green-threads, IoC (lifecycle, Props-based factories, ActorRef's), supervising, backpressure etc. Need only sequentiality (queue) + handler + state + message passing. As a side-effect I actually need small actor-based pipeline (with recursive links) + some parallell actors to optimize the DSP algorithm calculation. It will be inside library without transitive dependencies, so

What does a single apostrophe mean in Scala?

隐身守侯 提交于 2019-11-27 01:43:45
问题 In this slide show on ScalaActors.pdf what does the single quote indicate when the message is sent to the pong actor? class Ping(count: int, pong: Pong) extends Actor { def act() { pong ! 'Ping // what does the single quote indicate??? receive { case 'Pong => } } } 回答1: This defines a literal Symbol. See also this question. 回答2: It indicates a Symbol. Eg. cfr http://www.scala-lang.org/docu/files/api/scala/Symbol.html : the Scala term 'mysym will invoke the constructor of the Symbol class in

When to use actors in libgdx? What are cons and pros?

自作多情 提交于 2019-11-27 00:23:08
问题 I'm writing simple solar system simulator. This is my first libgdx project. I'm using a Stage and Actors for the main menu and is pretty handy especially touch events handling. But ... looking at the examples i see nobody uses actors in actual game logic. I wander if i should use actor as a parent of planet class or just write my own class tor that. The planets won't be touchable and they will be moved only between the frames so the third parameter of action MoveBy will have to be time

Scala final vs val for concurrency visibility

邮差的信 提交于 2019-11-26 22:45:27
问题 In Java, when using an object across multiple threads (and in general), it is good practice to make fields final. For example, public class ShareMe { private final MyObject obj; public ShareMe(MyObject obj) { this.obj = obj; } } In this case, the visibility of obj will be consistent across multiple threads (let's assume obj has all final fields as well) since it is safely constructed using the final keyword. In scala, it doesn't appear val compiles down to a final reference, but rather val is

How do I get hold of exceptions thrown in a Scala Future?

大憨熊 提交于 2019-11-26 21:31:13
问题 I've been working up my answer to Is there a standard Scala function for running a block with a timeout?, and have run into a problem if an exception is thrown in a Future. def runWithTimeout[T](timeoutMs: Long)(f: => T) : Option[T] = { awaitAll(timeoutMs, future(f)).head.asInstanceOf[Option[T]] } So that runWithTimeout(50) { "result" } should equal (Some("result")) runWithTimeout(50) { Thread.sleep(100); "result" } should equal (None) But if I throw an exception in my block it doesn't leak,

Parallel file processing in Scala

烈酒焚心 提交于 2019-11-26 21:00:32
问题 Suppose I need to process files in a given folder in parallel. In Java I would create a FolderReader thread to read file names from the folder and a pool of FileProcessor threads. FolderReader reads file names and submits the file processing function ( Runnable ) to the pool executor. In Scala I see two options: create a pool of FileProcessor actors and schedule a file processing function with Actors.Scheduler . create an actor for each file name while reading the file names. Does it make

mysql基本介绍和优化技巧

时光毁灭记忆、已成空白 提交于 2019-11-26 18:28:36
一. mysql框架和基本介绍 1. 框架图 更详细: 2. 存储引擎 MYISAM与INNODB对比: MYISAM:mysql5.1及以前版本的默认存储引擎。支持全文检索,压缩,表级锁等,但不支持事务,行级锁,崩溃后的数据恢复等 INNODB:mysql5.5及之后的默认存储引擎。支持事务,行级锁,数据恢复,mysql5.6 中的innodb(1.2)支持全文检索。 如何选择:innodb对于绝大多数的用户都是最佳的选择,除非某些存储引擎能满足特殊需求且使用者很了解这种存储引擎。 二. 查询性能的方法 1. 配置文件 my.cnf (linux), 读配置文件的一般顺序: 1) /etc/my.cnf 2) DATADIR/my.cnf 3) ~/.my.cnf 可以通过命令获知: mysqld --verbose --help | grep -A 1 'Default options’ 结果: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 2. 环境变量 从my,cnf读取环境变量值, 查看变量值方法: show variables like “”, (不清楚变量名时,用模糊匹配%) 例如 设置(全局)变量方法: set (global) 变量名=变量值 例如设置 开启慢查询日志 set