What advantages does Scala have over Java for concurrent programming?

前端 未结 3 1134
一整个雨季
一整个雨季 2021-02-04 08:03

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?

3条回答
  •  我寻月下人不归
    2021-02-04 08:13

    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)

提交回复
热议问题