• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What can Scala do for concurrent programming that Java can't?

 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again :-)

What puzzles me is the hype about Scala and in particular its pathbreaking concurrency features. Is there something new to it that can't technically be achieved with Java? Or is it more the way you have to think about concurrency problems in functional programming languages? Obviously there are actor implementations for Java, too, so I guess it's not impossible to achieve the same things in Java. But does anyone know what's the reason that this other way of thinking about concurrency hasn't gained broad popularity before?

Marco
 
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marco,
I'm not a Scala programmer, but I've been listening to some who are and as I understand it the main thing is that the tools for concurrency in Java are very low level. There's a great article on this at IBM Developer Works, here's the link to it: http://www.ibm.com/developerworks/java/library/j-scala02049.html

Burk
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Burk,

thanks for the interesting link. I'm going to read up on this ;-)

All these discussions about "low-level concurrency" in Java is something I don't really understand. Of course Java has all the things like the wait() or notify() methods or intrinsic locks etc. But do you really have to use it? At least starting with Java 5 there are a lot of higher level utilities, too. In my opinion most people who complain about the low-level support just use the wrong tools. What's easier than using a ThreadPoolExecutor for example which takes care of managing a thread pool for you? Of course you always have to be careful with shared state and all of its implications for concurrency. But that doesn't mean that it wouldn't be possible to create immutable objects and methods without side effects. Most programmers just don't care about concurrency issues because for a lot of traditional applications concurrency errors at runtime may be rare.

That said I really like the concepts and possibilites of Scala and I'm definitely going to put more effort into learning Scala. I just wanted to point out that a lot of the "advantages" could be achieved in Java, too. Maybe some things are harder, but not impossible. On the other hand I'm sure there are good reasons for all the hype about Scala's concurrency features, which I'd like t hear!

Marco
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marco,
I agree with you. The thing is that while you can make classes thread-safe in Java (if you know what you're doing ), Scala makes it easy and natural to do - or at least that's my understanding of it. I think the reason we're seeing more about concurrency is that it's more common to see machines with multiple processors, or multiple cores, now.
Burk
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the advantages of Scala is the power of having all the high level concurrency constructs in libraries but with the "feel" of being part of the core language.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The thing is that while you can make classes thread-safe in Java (if you know what you're doing ), Scala makes it easy and natural to do - or at least that's my understanding of it.


That's really true! If you're concerned about code quality and don't want to ignore the fact that code for multi-threaded environments simply has to be thread-safe to work correct in all situations, you soon start to realize how much trouble even simple data types like "Date" can cause because they are not immutable ;-)

That said, I understand that Scala encourages good coding habits and makes it easier to write thread-safe code. Anyway, I'd be glad to hear some not so well-known advantages Scala gives you for concurrent applications - additionally to built-in concepts for immutable value objects or side-effect free functions!

Marco
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That said, I understand that Scala encourages good coding habits and makes it easier to write thread-safe code. Anyway, I'd be glad to hear some not so well-known advantages Scala gives you for concurrent applications - additionally to built-in concepts for immutable value objects or side-effect free functions!



We should probably ask the experts for some of that, but the other thing I've heard is that Scala it considered "low ceremony" compared to Java in that it doesn't need a lot of the boilerplate code that goes along with checked exceptions.
 
Author
Posts: 135
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very reasonable question and I think the discussion that followed is pretty good as well. To add my 2 cents:
It is possible to write OO code in 'C' but would you? In a similar way, it is possible to write thread safe code in Java, but the
efforts are way too much. Scala makes it much easier. We still need discipline and good coding practices. However, it is easier
(a lot more easier) to follow a small set of these practices and write thread safe code in Scala than in Java. You can add more
libraries to Java, however, the idiomatic differences (immutability, side-effect free functions, closures, working with immutable
datastructures) along with powerful libraries of Scala and features like traits change the way you program and hence greatly
eases the burden.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Venkat,

thanks for clarifaction! So it seems we were on the right track

Of course you're right, just because something CAN be done in one programming language it's not necessarily the best or easiest way. Anyway, I'm astonished that better support for a few basic concepts like immutability for example obviously make a big difference.

Marco
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Venkat,
As time goes on, I've noticed that making something easy to do is often the little push needed to get more folks to do what they know they should be doing anyway.
Thanks for the reminder,
Burk
 
reply
    Bookmark Topic Watch Topic
  • New Topic