Tuesday, May 16, 2006

Realtime Java - Nearly there!

An interesting article on Sun's recent implementation of JSR-1 Java Realtime System (JRS) (finally!).

One of the interview questions I like to ask of anybody who has any sort of real-time systems experience on their resume is simply: How do you define real-time? I like to define something like: operations that must run within a bounded timeframe - not sooner, not later.

In Java the garbage collector behaviour (or the memory allocation pattern of the application, depending on your point of view), where major collections can freeze the application for seconds at a time, is the biggest inhibitor to real-time behaviour.

JRS provides the following real-time infrastructure:

  • Direct Memory Access. Does provide some bounds controls over raw C pointers.
  • Async communications. Including for events from outside the JVM.
  • Memory Management. Including the new immortal memory space (lasts for as long as the application, not subject to garbage collection).
  • Real-time threads. Priority levels that are strictly enforced.

While more helpful infra is now there, one trick I've always used to make applications more real-time (in both Java and C++) is to allocate as much of the application's total memory needs as possible when the application firsts starts up. This involves pre-loading any reference data and trying to "recycle" objects instead of allowing them to be garbage collected. A good library that is built along these thoughts is the excellent Javaloution. JRS would be even better if it incorporated some of these memory management ideas.

No comments: