Scala对Java进行并发编程有什么优势? [英] What advantages does Scala have over Java for concurrent programming?

查看:147
本文介绍了Scala对Java进行并发编程有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scala如何使编写多线程程序比在java中更容易? scala能做些什么(java不能)以利用多个处理器?

How can scala make writing multi-threaded programs easier than in java? What can scala do (that java can't) to facilitate taking advantage of multiple processors?

推荐答案

并发规则是

1如果可以,请避免

2如果可以,则不分享

2 share nothing if you can

3分享不可变对象如果你可以

3 share immutable objects if you can

4要非常小心(和幸运)

4 be very careful (and lucky)

对于规则2,Scala通过以actor的形式提供一个开箱即用的完美集成的消息传递库来提供帮助。

For rule 2 Scala helps by providing a nicely integrated message passing library out of the box in the form of the actors.

对于规则3,Scala有助于使所有内容不可变默认。

For rule 3 Scala helps to make everything immutable by default.

对于规则4,Scala灵活的语法允许创建内部DSL,使其更容易,更少冗长,无法表达您需要的内容。即减少意外的地方(如果做得好)

For rule 4 Scala's flexible syntax allows the creation of internal DSL's making it easier and less wordy to express what you need consicely. i.e. less place for surprises (if done well)

这篇关于Scala对Java进行并发编程有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆