Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What advantages does Scala have over Java for concurrent programming?

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?

like image 255
Gordon Gustafson Avatar asked Aug 20 '10 23:08

Gordon Gustafson


People also ask

Why is Scala good at concurrency?

Scala got a fame for being good for concurrency because it is a functional language and because of its actors library. Functional languages are good for concurrency because they focus on immutability, which helps concurrent algorithms.

Which language is best for concurrent programming?

A programming language designed to support simultaneous operations. For example, Java and the Java-like Scala language natively support threads and synchronization, whereas languages such as C and C++ rely on external libraries for programming concurrency.

Does Scala support concurrent programming?

Although Scala is still a language on the rise that has yet to receive the wide-scale adoption of a language such as Java, its support for concurrent programming is rich and powerful.

Is Scala more efficient than Java?

Scala vs Java performance Some coders claim that Scala is a little bit faster than Java programming with 20% fast processing. Optimization in Scala language makes code compilation much faster than Java coding.


1 Answers

The rules for concurrency are

1 avoid it if you can

2 share nothing if you can

3 share immutable objects if you can

4 be very careful (and lucky)

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

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

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)

like image 59
Peter Tillemans Avatar answered Oct 14 '22 17:10

Peter Tillemans