InfoQ

News

Multi-core Processors: Good or Bad for Java

Posted by Scott Delap on Nov 27, 2006 11:01 AM

Community
Java
Topics
Programming ,
Performance & Scalability
Tags
Multi-threading ,
Java EE
Two recent items on the internet have looked at the topic of multi-core processors and Java. A recent article by Randall Scarberry of JavaWorld.com looks at using the Java concurrency API to write multi-threaded algorithms. Billy Newport of IBM also recently written a blog post detailing how Java may not be well suited for multi-core processors.

The JavaWorld article looks at the process of taking a single threaded algorithm and converting it to be multi-threaded. The basic approach is outlined as:

  1. Develop a single-threaded, sequential, robust, and clearly organized version of your algorithm. If you're reading this article to speed up something that exists, you may already have this step covered.
  2. Identify the subtasks. Examine the algorithm to identify the discrete stages. This shouldn't be difficult if you performed Step 1 adequately. Each subtask probably has its own method, or at least a clearly-delineated block of code. If you have difficulty identifying the subtasks, you probably need to understand the algorithm better or reorganize your code. In that case, return to Step 1.
  3. Benchmark the algorithm. In other words, time the identified subtasks to determine the fraction of time consumed by each. This should be a trivial matter of adding some timing and output statements.
  4. Delegate the most time-consuming subtasks to a thread pool. Now we come to the most difficult part: reorganizing your code so the slowest subtasks are performed concurrently by multiple subtask threads. Luckily, two utility classes in java.util.concurrent greatly simplify the process.

The article then continues by taking a K-Means algorithm and multi-threading it using java.util.concurrent API features such as ThreadPoolExecutor and CyclicBarrier.

A TSS discussion on this article generated a number of interesting comments of multi-threading in respect to JEE.

...First of all, most J2EE applications are heavy transaction based applications. At least the ones that I work on in the financial industry. Because of the J2EE specification, you can't be spawning threads. You also can't have multiple threads accessing the same transaction. It just doesn't work.

A way of breaking up large chunks of work into smaller managable is to use JMS to leverage the container to do the multi-threading for you. But once again, you have to take into account the transactions and keep track of those chunks of work in different transactions.

J2EE applications already take advantage of multi-core, multiple CPUs already. Every applications server uses some sort of multiple threads, weather that is in an execute queue or (gasp) spawning a new thread for each connection.

Billy Newport responds:

...I beg to differ. If only the simple threading models offered by typical containers were adequate for the diversity of applications out there. I added the WorkManager spec to WebSphere and then standardized it using the commonj APIs for exactly this purpose. There are clever people out there who can be trusted to write threaded code and commonj lets them build J2EE applications using a threading model thats appropriate for the application rather than the boiler plate models provided by the vendors. Yes, JMS can be used as a way to do it also but it's millions of times slower than native threading...

This comment is followed by a blog post on why multi-core may actually be bad for Java. Among the items he notes:

  • Java likely has a longer path length than languages like C and clock speeds won't help with this.
  • JavaEE promotes a simple threading model for applications
  • Garbage collection remains heavily dependant on clock speed for small pauses.
Multicore on the desktop by Fabrizio Giudici Posted Nov 27, 2006 1:04 PM
Re: Multicore on the desktop by cstar cstar Posted Nov 29, 2006 6:49 AM
Re: Multicore on the desktop by Billy Newport Posted Nov 30, 2006 7:54 PM
  1. Back to top

    Multicore on the desktop

    Nov 27, 2006 1:04 PM by Fabrizio Giudici

    I'd just like to point at my blog on java.net where I dealt with the multi-core + Java, more in a desktop perspective. I've seen a bunch of blogs on this subject, each in a slightly different perspective, in a few days. It's good that people talks about it, as it will be something to deal with in the near future.

  2. Back to top

    Re: Multicore on the desktop

    Nov 29, 2006 6:49 AM by cstar cstar

    The problem is not multi-core is good or bad for Java. The top of the line for IBM AMD and Intel are all multi-core. Java must adapt if necessary to run on these architectures.

  3. Back to top

    Re: Multicore on the desktop

    Nov 30, 2006 7:54 PM by Billy Newport

    Hit the nail right on the head. Things and assumptions are changing and there will be changes as a result. Hopefully, Java JVM JITs can be designed to optimise for the processor architecture where they are running as well as expected workloads.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.