The Java parallelism paradox

Java 8 has been reengineered with the strength of Project Lambda Expressions.

Lambda, is a Java function that adds ‘closures and related features’ dedicated to supporting multicore programming.

a ScienceDuke150.jpeg

A Lambda expression is code that a developer can “share” to be executed later, just the once or executed multiple times — hence, more control exists for parallelism over multicore.

This is important because as Herb Sutter said in Dr Dobb’s Journal back in 2005, we are at a “fundamental turning point in software development” — this was in his piece entitled The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software

Up until Java 8, this is what Oracle’s Java Tutorial page had to say about parallelism:

Parallel computing involves dividing a problem into sub-problems, solving those problems simultaneously (in parallel, with each sub-problem running in a separate thread), and then combining the results of the solutions to the sub-problems.

So looking back, Java SE provided the fork/join framework, which enables developers to implement parallel computing in applications.

However, with this framework, the programmer must specify how the problems are subdivided (partitioned).

With Java 8, Oracle explains that it is taking some of the dirtier mechanics out of the equation and essentially making the whole route to parallelism easier to get to.

Java SE vice president George Saab explained to reporters in Prague this week that he is thinking about parallelism and concurrency and how the Java team now works with developers to exploit the potential here with Lambda.

Saab notes that you could achieve parallelism with Java closures previously (as Java 8 now provides) via abstract inner classes, so this will not be completely alien to developers who could no doubt have been using parallelism elsewhere also as well as Fork/Join Framework tools (JSR166y).

The proposition with Lambda is that it takes some of the mechanics out of this process and makes it more automated.

Going back further, vice president of development for the Java platform Nandini Ramani points out that Java has a history of parallelism as Phasers were introduced in 2006 with Java 7 (JSR166) and further still all the way back to Java 1.4 with java.lang.Thread if you want to do the history.

Plus let’s also not forget… Lambda (as a working project with builds) has been around since JDK 7.0 so it has had time to bake.

Whichever way you slice it, Java is ready (or more ready at least) for parallelism and the free (developer) lunch is indeed over.