Is concurrency built in into Scala?


#1

Is concurrency a part of Scala or I need to use something called as Akka.

I’m sorry for the noob question, beginner to this awesome language !


#2

No need to appoligize :slight_smile:

Akka is a system which make concurrency easier to manage, but on it’s own, Scala has some concurrency features.


#3

The language doesn’t inherently have any special concurrency features, but there are many libraries to help you!

If you’re just looking for “run this on another thread and tell me when it’s done” then you probably want the standard library’s Futures. There’s also Monadless which helps you work with Futures as if they were normal values, which is very convenient for code that has to merge futures from different sources.

If you want to stream multiple results (for example, if you’re listening for changes), then Monix is probably what you want. If you’ve used any of the Rx/ReactiveX libraries then you’ll feel right at home.

Akka is, IMO, the “big guns” for when neither of the above solutions are enough. The upside is that it lets you communicate thread-safely with pretty much any pattern you need. The downside is that you lose type safety, and that there’s a lot of extra boilerplate, for stuff that the options above give you “for free”.

Of course, since it’s a JVM language, you could also just use plain threads directly. I wouldn’t recommend it though.


#4

Thank you for the quick reply!!

Great !! Looking forward to scala’s concurrency features !


#5

Hello,

Futures https://docs.scala-lang.org/overviews/core/futures.html are a
very popular way.

If Futures are not enough, you can use in Scala anything that is in the
Java standard library, such as creating your own Threads
https://docs.oracle.com/javase/tutorial/essential/concurrency/.

Best, Oliver


#6

Doesn’t AnyRef#synchronized count as a language feature?