Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 790
GedankenNebel Avatar asked Jun 07 '13 10:06

GedankenNebel


1 Answers

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

collection.map { // 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.

like image 193
Brian Agnew Avatar answered Sep 28 '22 18:09

Brian Agnew