Skip to main content

The State of Java: Meeting the Multicore Challenge

Posted by editor on December 21, 2011 at 4:52 PM PST

"The multicore challenge" is the challenge to developers of software products to write code that effectively utilizes modern multi-core / multi-processor computers. Two years ago, I wondered if the multicore challenge was still relevant. In part, I was thinking about how applications were moving from the desktop into the cloud. So, if the apps people are running are running in a browser, does it matter if their desktop system (or pad or phone) is multicore?

Today many mobile phones can really be looked at as being computers. In an article about the contributions mobile phones are making in poor countries, the Economist noted that "Mobile phones are the world's most widely distributed computers." And many of the newer mobile phones are multicore.

So really, whether the target computer for your software is a traditional tower, a laptop, a pad, or a phone, the multicore challenge remains relevant today -- and its relevance will only increase in the coming years. Browsers, one would think, are going to have to evolve to utilize multiple cores and processors. The ones that do so will ultimately take away significant market share from the ones that don't. How they'll accomplish this is another question...

Java already has basic capabilities for utilizing multiple processors -- in the threads library, for example. But, clearly that's considered inadequate for meeting the needs of the future. Which is why we have JSR 335: Lambda Expressions for the Java(TM) Programming Language. The development of JSR 335 takes place in Project Lambda, a component of the OpenJDK project.

At JavaOne 2011, Alex Buckley presented a very well attended session titled "Project Lambda: To Multicore and Beyond" that outlined the vision and plan for bringing Lambda expressions into Java. This will happen in Java 8 -- so, we're still a ways away from having a formal release.

The key element, in my view, is that Lambda expressions (also called "closures") will be implemented largely via a rewrite of the underlying JDK libraries wherein they will "automatically" do the low-level work of divying up the task at hand and passing segments of it to the available processor cores. This will enormously reduce the effort for Java application developers to convert their existing programs such that they can utilize multiple processors/cores.

Writing multithreaded code is hard. I've been doing it for 18 years, starting out on 8-processor Sun machines where we took scientific C and Fortran code delivered by researchers and revised it to parcel out data segments to different threads. Tiny mistakes inevitably result in overwritten data, which produces non-repeatable erroneous results, crashes, hung threads, and other "fun" head-scratchers... Yeah, it's hard to write threadsafe code!

The approach taken by the Java 8 architects and developers is going to in essence hide all that complicated threading stuff from the higher level app developer, by implementing the multithreading and fork/join processing within the Java libraries themselves. This is an enormous effort in itself, but it's a much smaller effort than if every Java application development team had to multithread their apps, having to rewrite function after function to be threadsafe.

Of course, the efficiency of the apps on multicore computers will thus depend on how much of the processing actually occurs within the core Java libraries. It's not going to be a situation where, because of Project Lambda, all apps will suddenly utilize all available cores 100% of the time, and immediately speed up by nC times (where nC is the number of cores in the computer).

Still, Project Lambda is a major innovation, a key step into the future for Java.

If you find all this interesting, you may want to take a look at Mike Duigou's JavaOne 2011 presentation "Bulk Hauling: Parallel Data and Lambdas in Java 8." The PDF for that is available in the JavaOne Content Catalog.


java.net Weblogs

Since my last blog post, quite a few people have posted interesting new java.net blogs:


Poll

Our current java.net poll asks you to respond to The most important Java/JVM related happening in 2011 was. Voting will be open until Friday, December 23.


Articles

Our latest java.net article is SWELL - An English-Like DSL for Swing Testing by Sanjay Dasgupta and Chirantan Kundu.


Java News

Here are the stories we've recently featured in our Java news section:


Spotlights

Our latest java.net href="http://www.java.net/archive/spotlight">Spotlight is Pieter Humphrey's OTN Virtual Developer Day returns! WebLogic Server 12c, Coherence in Jan/Feb 2012 :

Join us for a new breed of free, hands-on virtual developer workshops at Oracle Technology Network's Virtual Developer Day. Java Developers and Architects can attend live moderated sessions and hands on labs at the event, where you will learn about how Oracle WebLogic Server 12c and Oracle Coherence are the foundation for modern, lightweight development...

Previously we featured David Heffelfinger's new article Spring to Java EE Migration, Part 2:

In this part, we continue rewriting the Pet Clinic application, once again fully taking advantage of the Java EE tooling available in NetBeans. We develop Enterprise JavaBeans (EJB) 3.1 session beans that act as our Data Access Objects (DAOs), as well as JavaServer Faces (JSF) 2.0 managed beans and pages...


Subscriptions and Archives: You can subscribe to this blog using the java.net Editor's Blog Feed. You can also subscribe to the Java Today RSS feed and the java.net blogs feed. You can find historical archives of what has appeared the front page of java.net in the java.net home page archive.

-- Kevin Farnham

Twitter: @kevin_farnham

Related Topics >>