I am rather confused about what approach to take while writing multithreading code in Scala. I see three options:-
- 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
- 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.
- 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.