GedankenNebel GedankenNebel - 1 year ago 190
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download