1

I am rather confused about what approach to take while writing multithreading code in Scala. I see three options:-

  1. Use Java style.. and use Scala where there are syntax issues.. e.g. there is no volatile keyword in Scala but fields can be marked volatile with @volatile, and there is no synchronized allowed on functions, but this.synchronized can be used
  2. As far as possible, use scala.concurrent.impl package. This has a Scala specific Future, FutureTasks etc. Then there is scala.collection.mutable which offers various collections like PriorityQueue, SynchronizedBuffer, SynchronizedMap, some of which are deprecated and the docs suggest to use java.util.concurrent(!) which makes things even weirder.
  3. Finally, there is Akka, which some say that it will become part of Scala release and will be default way of multithreading.. I am not so sure.
    Can someone tell me which is the right approach for a straightforward multithreading app... e.g. if I am writing a producer consumer kind of app with multiple producer threads and multiple consumer threads, which is right scalaistic way.
    Akka seems overkill.
    I don't understand why Scala libraries provided their own concurrent data structures.. some of which are deprecated, and don't even provide any additional functionality over Java concurrent packages.
1
  • Akka is not overkill. Akka actors is specifically made for this kind of requirements .You can use Akka-actors package only instead of entire akka. Commented Sep 12, 2016 at 3:51

2 Answers 2

1

My advise would be to start with Futures and then move to Actors if there is a need.

Sign up to request clarification or add additional context in comments.

Comments

0

Akka is more then just multithreading. It's a framework for distributed applications / jobs. If you have to implement multiple consumer / producer threads, I'd recemmend you akka.

Maybe have a look at distributed pub-sub section of the documentation. Seems to address your problem pretty much: http://doc.akka.io/docs/akka/current/scala/distributed-pub-sub.html

If akka's too complex to get started, use Scala Features. Theres a good series of articles about Scala features at https://github.com/viktorklang/blog

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.