WOW! Multi-core processing a snap with Spring 3

For many years, processor speed was measured by the frequency of the processor (the number of MHz or GHz). As chip makers have squeezed more and more transistors into the same amount of space, physical limitations have prevented processors from running at faster frequencies. So, to keep creating gains in processor speed, chipmakers have increased the number of cores on the processor instead of raising the frequency. Additional cores allow the processor to do additional things at once. For example, if there are 4 cores that is theoretically 4 times more powerful than a processor with 1 core running at the same frequency.

In practice, most programmers are not used to supporting multiple processors, so the software they write can only take advantage of a single core. This means all that extra processing power sits idle. Fortunately, the Spring team, along with the rest of the Java community, has come up with a very elegant approach to supporting multiple processors.

Today for my R&D; project, I changed our background score calculation process so that it can take advantage of more than one processor core. It only took a couple hours from the time I started reading the documentation to the time I had my code working. I couldn't believe how easy it was! I will definitely keep an eye out for other places in our software that could take better advantage of multiple processing cores.

For the technical folks out there, here are the resources I used to get me up to speed so quickly. I used Spring's @Async annotation, Java 5's java.util.concurrent.Future class and Spring's org.springframework.scheduling.annotation.AsyncResult.

@Async
Future<?> getMyResultAsynchronously() {
    Object result = // set the result to whatever you want returned
    return new AsyncResult(result);
}