GedankenNebel GedankenNebel - 8 months ago 72
Java Question

What are the advantages of Lambda Expressions for multicore systems?

The Java Tutorials for Lambda Expressions says following:

This section discusses features included in Project Lambda, which aims
to support programming in a multicore environment by adding closures
and related features to the Java language.

My question is, what concrete advantages do I have with Lambda Expressions according to multicore systems and concurrent/parallel programming?


Parallelism is trivial to implement e.g. if you have a collection and you implement a lambda thus: { // my lambda }

then the collection itself can parallelise that operation without you having to do the threading etc. yourself. The parallelism is handled within the collection map() implementation.

In a purely functional (i.e. no side effects) system, you can do this for every lambda. For a non-purely functional environment you'd have to select the lambdas for which this would apply (since your lambda may not operate safely in parallel). e.g. in Scala you have to explicitly take the parallel view on a collection in order to implement the above.