actor

Scala final vs val for concurrency visibility

随声附和 提交于 2019-11-27 19:02:24
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 semantics in scala that prevents you from reassigning a variable ( Scala final variables in

Is it bad practice to send an actor a message from something which is not an actor?

*爱你&永不变心* 提交于 2019-11-27 18:12:41
问题 Suppose I have some class which has a property actor_ of type Actor . Is there a problem with me doing def someMethod() = { actor_ ! "HELLO" } Or should sending a message always be done from another actor; e.g. def someMethod() = { Actor.actor { actor_ ! "HELLO" } } 回答1: It depends. When you send a message to an actor from non-actor code, an ActorProxy is automatically created and stored in a thread local. This creates a potential memory leak, albeit a very small one, because the ActorProxy

牛客——数据库实战(31~61)

我与影子孤独终老i 提交于 2019-11-27 15:58:01
文章目录 31. 获取select 32. 将employees表的所有员工的last_name和first_name拼接起来作为Name,中间以一个空格区分 33. 创建一个actor表,包含如下列信息 34. 批量插入数据 35. 批量插入数据,如果数据已经存在,请忽略,不使用replace操作 36. 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表 37. 对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname 38. 针对actor表创建视图actor_name_view 39. 针对上面的salaries表emp_no字段创建索引idx_emp_no,查询emp_no为10005, 40. 在last_update后面新增加一列名字为create_date 41. 构造一个触发器audit_log,在向employees表中插入一条数据的时候,触发插入相关的数据到audit中 42. 删除emp_no重复的记录,只保留最小的id对应的记录。 43. 将所有to_date为9999-01-01的全部更新为NULL 44. 将id=5以及emp_no=10001的行数据替换成id=5以及emp_no=10005,其他数据保持不变

mysql高效索引之覆盖索引

依然范特西╮ 提交于 2019-11-27 14:49:22
概念 如果索引 包含所有满足查询需要的数据的索引成为覆盖索引(Covering Index),也就是平时所说的不需要回表操作 判断标准 使用explain,可以通过输出的extra列来判断,对于一个索引覆盖查询,显示为 using index ,MySQL查询优化器在执行查询前会决定是否有索引覆盖查询 注意 1、覆盖索引也并不适用于任意的索引类型,索引必须存储列的值 2、Hash 和full-text索引不存储值,因此MySQL只能使用B-TREE 3、并且不同的存储引擎实现覆盖索引都是不同的 4、并不是所有的存储引擎都支持它们 5、如果要使用覆盖索引,一定要注意SELECT 列表值取出需要的列,不可以是SELECT *,因为如果将所有字段一起做索引会导致索引文件过大,查询性能下降,不能为了利用覆盖索引而这么做 InnoDB 1、覆盖索引查询时除了除了索引本身的包含的列,还可以使用其默认的 聚集索引列 2、 这跟INNOB的索引结构有关系,主索引是B+树索引存储,也即我们所说的数据行即索引,索引即数据 3、对于INNODB的辅助索引,它的叶子节点存储的是索引值和指向主键索引的位置,然后需要通过主键在查询表的字段值,所以辅助索引存储了主键的值 4、覆盖索引也可以用上INNODB 默认的聚集索引 5、 innodb引擎的所有储存了主键ID,事务ID,回滚指针,非主键ID

Scala remote actors

可紊 提交于 2019-11-27 13:00:30
问题 Are there any guides or tutorials which explain the possibility to use scala actors remotely? All I have found until now is one example (without comments) but that's hardly enough. 回答1: I have written an article with an example app to explain the use of Remote Actors a bit some time ago. Well, it has no comments inside the code (maybe you even meant that article), but there are explanations below the code. 回答2: Just be careful to send messages that are serializable (case classes and case

Orleans简介

风流意气都作罢 提交于 2019-11-27 12:38:08
Orleans简介.   Orleans是微软开源的分布式actor模型框架.actor模型的原理网络上有很多文章.有许多理论性的文章,深刻地我都不知道怎么应用.在这里我就不赘述了.既然是博客,就说说自己的理解。 对于编程来说,不管是前台还是后台,在现在的计算机环境下,多线程编程是不可避免的。多线程带来的很多好处,也带来的很多编程上的“坏处”。好处就是,什么并发、高效,高资源利用率等等高大上的词语。这些就不详细说了。就说说坏处. 多线程带来的最大的变化就是:我先前保存的变量A,在我想要再次利用它的时候,A是否被其他线程给更改了?数据库中叫脏读,我们拿过来用,“避免脏读”又有个同义词叫做“操作的原子性”。为了解决脏读的问题,有一下几种办法:   办法一变量A在初始赋值的时候,就规定它不可以被更改,就是不可变,英文叫做immutable,很多函数式语言如F#,scala等都有不可变量。既然量是不可变的。就不会有什么脏读问题了。这真是个好办法,但是在C#和JAVA这样的语言里,这不是个好办法。   办法二就是大家经常使用的,多线程,架锁。精巧的设计类,小心的使用这些来,管理各种资源的竞争。为了避免脏读,在C#以及JAVA里,架锁是一个可行的办法。但是这样会使得效率变低(锁架地多了,这个会更明显),更为关键是带来逻辑的复杂性。架锁的程序,可以说是一个“正确但是脆弱”的程序。离开了初创人员

How to restrict actor messages to specific types?

匆匆过客 提交于 2019-11-27 12:19:31
In Akka , is there a way to restrict messages to actors to be of a specific static type other than using the "Typed Actor" APIs that use an RPC style programming model? Can I use the message passing style with Akka without throwing away static type safety at the actor boundaries? For example, I'd like to use code like this: sealed abstract class FooMessage case object Foo extends FooMessage case object Bar extends FooMessage class FooActor extends Actor[FooMessage] { def receive = { case Foo => () // OK // Would raise a compiler error: // case s: String => error("Can't happen, String is not a

Can Scala actors process multiple messages simultaneously?

我的未来我决定 提交于 2019-11-27 10:37:18
The reply to a recent question of mine indicated that an actor processed its messages one at a time . Is this true? I see nothing that explicitly says that (in Programming in Scala ), which contains the following snippet (pp. 593) If [the react method] finds a message that can be handled, [it] will schedule the handling of that message for later execution and throw an exception (Emphasis my own). Two related (and mutually exclusive) questions: Assuming an actor could process multiple messages simulatenously, how can I force an actor to process messages 1 at a time (if this is what I wish to do

How does Actors work compared to threads?

非 Y 不嫁゛ 提交于 2019-11-27 09:04:52
问题 Is there any good and short explanation of how Actors works compared to threads? Can't a thread be seen as an actor and send messages to other threads? I see some difference, but it's not that clear for me. Can I use Actors in any language by using threads differently? 回答1: The actor model operates on message passing. Individual processes (actors) are allowed to send messages asynchronously to each other. What distinguishes this from what we normally think of as the threading model, is that

How are the multiple Actors implementation in Scala different?

这一生的挚爱 提交于 2019-11-27 08:58:26
问题 With the release of Scala 2.9.0, the Typesafe Stack was also announced, which combines the Scala language with the Akka framework. Now, though Scala has actors in its standard library, Akka uses its own implementation. And, if we look for other implementations, we'll also find that Lift and Scalaz have implementations too! So, what is the difference between these implementations? 回答1: This answer isn't really mine. It was produced by Viktor Klang (of Akka fame) with the help of David Pollak