Fear multicore apps? Reactive programming to the rescue

Java is fast becoming a platform for coding programs that react to events rather than simply executing a string of commands

Reactive programming, in which programs react to events, is gathering steam as a mechanism for programming on multicore processors and for Web development. The concept is growing in importance in the Java realm, in particular. Typesafe, which has built its Akka middleware stack around the Scala language and reactive programming, is an advocate, and Netflix has been touting functional, reactive programming with its RxJava library for asynchronous and event-based programs, based on Microsoft's Reactive Extensions project.

InfoWorld Editor at Large Paul Krill met with Typesafe Senior Software Engineer Josh Suereth at the recent JavaOne technical conference in San Francisco to talk about reactive programming. Suereth also commented on the importance of Lambdas in the upcoming Java Standard Edition 8 release.

InfoWorld: What is reactive programming?

Suereth: It's a concept that really has been around for a long time, but it's now becoming viable for Java. The basics of it is essentially instead of writing code that you say, "Do this, do this, do this, do this," you say, "After this event, do something. After that is complete, do something." So it's about reacting when something is done. The main reason this matters is because as we go multicore, if you program in this style, there are new techniques to optimize across CPUs.... I would say [reactive programming is becoming important now] because of the explosion in cores on CPUs. You're no longer able to stick your logic on a single thread and have that be the most efficient path. In the past, it definitely was. And now we're starting to see less CPU utilization, and we need to improve it. This is a mechanism that will let us improve utilization of the CPU and still retain performance.

InfoWorld: New techniques as far as what?

Suereth: Java 7 introduced the fork/join library where if you program in a reactive style the fork/join library can actually retain some really good performance characteristics in that style. Similar to if you were writing just sequential code.

InfoWorld: Is reactive programming intended for Web development?

Suereth: It's really for any development, but I think it really shines when you're doing Web [application] development.

InfoWorld: Why?

Suereth: Just the nature of that style of programming. You get a request, and on that request, you have to perform some work, and that work usually entails making requests to other services that come back later, and you want to try to make sure when you're responding to these requests that you're not passing the data just across the CPUs and threads willy-nilly. You want to keep it local to where it comes in. So this way of partitioning your workflow can help the framework optimize your code.

InfoWorld: Which framework?

Suereth: In this particular case, I think the best example of this style is the Play Web Framework. It started off as a Java-only framework, and now the core is written in Scala; Typesafe is the primary provider. It's actually designed by Zenexity, a consulting company in France.

1 2 Page 1
Page 1 of 2