Big Data. Big Decisions
InformationWeek
Special Coverage Series


Dr. Dobb's Report: Real-Time Ready Java

Predictable, real-time performance is possible By Eric J. Bruno

Java has long been one of the central technologies of enterprise applications. The speed and scalability of the JVM, in particular, have endeared it to large IT organizations. But today, companies need more than just fast performance; they are increasingly searching for deterministic, real-time performance.

Determinism in this sense means that a given action will occur within a fixed time interval, such as delivery of a stock quotation within some number of microseconds. Historically, Java hasn't been used to fill that role, because of some early design decisions in the platform. However, new options and new technologies are enabling IT organizations to use Java for both standard business needs and situations where deterministic, real-time requirements must be met.

More Insights

Webcasts

More >>

White Papers

More >>

Reports

More >>

Few things generate more confusion in the programming world than discussions of real-time software. Many confuse it with high-performance computing, while others use it to describe any system that pushes data to the user without a user request. These characterizations alone simply aren't accurate. While it's true that both these aspects may be part of real-time system behavior, the definition of a real-time system centers on one word: time. Correctness means producing the right answer, and doing so at a precise moment in time.

Another source of confusion is the difference between hard and soft real-time systems. A hard real-time requirement is one in which a task needs to be completed at or before a certain time, every time it's required, regardless of other factors. A soft real-time system contains some tolerance in terms of missing its deadline.

For example, stating that a foreign exchange trade needs to settle within two days is a hard real-time requirement, whereas stating that video player software needs to update its frame 60 times per second is a soft real-time requirement--occasionally dropping a frame isn't considered an error. However, it's still a real-time system because too many dropped frames, or too much delay between them, is considered an error.

Java And Real-Time Development

Java Standard Edition (Java SE) is not ideally suited for real-time requirements. Existing Java Virtual Machines (JVMs) just aren't designed for predictability and determinism.

For instance, garbage collection (GC), in which the RAM allocated to no-longer-used data items is reclaimed for reuse by the JVM, is one source of trouble. GC can occur at any time, for any length of time, with few options for users to control it. This potential for unbounded delays makes it impossible to guarantee a system's behavior; it is nondeterministic. Attempts to pool objects or somehow control their lifetime to avoid GC are often in vain, as GC pauses may still occur.

However, Java SE's real-time deficiencies go beyond the garbage collector. The just-in-time (JIT) HotSpot compiler--the same one that compiles bytecode to machine code--is also nondeterministic. Because JIT compilation can occur when your code is executing, and can take an unknown length of time to complete, you can't be guaranteed that your code will meet its deadlines all the time. Even Java classes that have been JIT-compiled are subject to reoptimization at any point in the future.

More importantly, Java provides no guaranteed way to prioritize threads or event handling within your application code. Therefore, even if GC and JIT could be controlled, real-time behavior couldn't be guaranteed without the ability to prioritize your thread processing. With strict priority control comes the need for advanced locking beyond what most standard JVMs provide. These are important points to remember as most people blame the GC and JIT compiler entirely for Java's lack of real-time ability.

The C++ Alternative

A common alternative to Java for real-time development is C++, but this is a flawed solution. While C++ is a good language, it isn't an entity that magically yields predictability and determinism. It requires great skill and enormous knowledge, along with operating system support and integration, to deliver a real-time system in C++.

For instance, although GC problems don't exist in C++, the C runtime on which C++ depends for heap management can exhibit nondeterministic behavior. Quick examination of some standard C runtime library code reveals that locating free memory chunks for use by the program can involve extensive memory manipulation. This can lead to unpredictable results during memory operations.

Instead, with C++, the developer bears a great burden to ensure deterministic, predictable execution across all aspects of application processing. This usually results in a dependence upon third-party libraries for memory management, thread processing, and interaction with the operating system for I/O operations. These are all features that the Java VM provides built-in. Used correctly, the JVM can perform these operations while providing support for real-time development. Here's how.

Real-Time Java Solutions

In the late '90s, a group of real-time and programming language experts from around the globe worked together to define a specification to define how Java should behave in the real-time space. The result was the Real-Time Specification for Java (RTSJ), which doesn't change the Java language at all, but instead outlines areas of enhancement to the platform to meet real-time requirements. These include:

>> Thread scheduling: The RTSJ states that a real-time scheduler be used to schedule tasks, but it doesn't specify the algorithm, nor how to do it. RTSJ implementations typically rely upon and work with the OS to achieve this goal. RTSJ does, however, define new thread types--i.e. RealtimeThread (RTT), and NoHeapRealtimeThread (NHRT)--for real-time Java execution.

>> Memory management: The RTSJ doesn't require a garbage collector, nor does it specify any algorithms for it. Instead, it defines new memory regions beyond the heap, and specifies that the collector not interfere with them. Therefore, it's possible to perform memory management outside the scope of the Java GC.

>>Resource sharing: With enhanced thread scheduling comes the need for thread priority control. The RTSJ requires the priority inheritance protocol be implemented through the Java synchronized keyword, along with a set of wait-free queues.

>> Asynchronous execution control: To control asynchronous event handling, the RTSJ defines how event-handling code is to be scheduled and dispatched deterministically. It also extends the Java Exception handler to allow immediate shifts of execution within a real-time thread. Finally, it defines a way to terminate a thread's execution safely and deterministically.

>> Physical memory access: The ability to create and access objects within specific regions of physical memory is defined, allowing Java code to interact with I/O and other hardware devices deterministically, and with minimal latency.

The overarching goal of the RTSJ is not to change the Java language (for example, it included no new keywords) but to allow the average Java developer to build real-time software. However, that's not to say some changes in coding practice aren't required. Let's take a quick look at how the RTSJ affects Java programming.

RTSJ In Practice

The Java developer needs to embrace some new concepts to use RTSJ. For instance, the two new thread classes described previously require developers to specify certain aspects of their behavior. These include priority, scheduling behavior (periodic or aperiodic), and memory region requirements. For instance, while an RTT can access objects that reside anywhere, an NHRT can't access objects that reside on the heap.

The RTSJ defines additional memory regions where objects can reside, to ensure no interference with the Java garbage collector. These regions include ScopedMemory, ImmortalMemory, and PhysicalMemory. A ScopedMemory region is an area of memory outside of the Java heap that can be defined and created at runtime, and within which Java objects are created. When the real-time code finishes with the region (something the developer controls), the entire region and the objects it contains are marked as free, and all references to them are removed; no GC is required.

The sole ImmortalMemory region is an area of memory where Java objects live for the life of the VM. Objects created here are never collected, nor are they freed in any way. Hence, ImmortalMemory is a limited resource meant to provide deterministic access to data commonly needed within a real-time Java application.

There are sometimes complex rules for object reference and access between the various memory regions, but I won't go into those details here. Those details as well as asynchronous event handling, asynchronous transfer of control, and physical memory access can be reviewed in the RTSJ document or in one of the books written on the topic.

Real-Time Java Implementations

RTSJ has seen a few revisions over the years, and it's still actively being improved. For instance, JSR-282 is in the early draft review stage, and will define version 1.1 of the RTSJ. Be sure to look at the current specification, and then the proposed revision, to get a feel for where things are headed.

Officially compliant RTSJ implementations include the Sun (now Oracle) Java Real-Time System, the IBM WebSphere Real-Time VM, and the Timesys RTSJ reference implementation. Both Oracle and IBM provide support for multiple operating systems, including Solaris and specific Linux distributions (real-time scheduler required).

There are no RTSJ-compliant implementations available for Windows, but not because of the common misconception that Windows can't provide real-time behavior. To some degree it can, via its real-time thread support, but it simply doesn't provide enough real-time thread priority levels to meet the RTSJ's requirements.

The common Linux distributions also don't meet the RTSJ's requirements for real-time systems. Instead, IBM provides its own real-time Linux variant to guarantee real-time behavior, and Oracle requires you use either Red Hat's Messaging-Realtime-Grid Linux distribution, or Novell's Suse Linux Enterprise Linux extensions for Suse Linux Enterprise Server.

Real-Time, Without RTSJ

There are other real-time Java implementations that aren't strictly RTSJ-compliant, although they may implement most or part of the API. These include:

>> Aicas JamaicaVM: A Java SE/ RTSJ-compatible implementation with a real-time, deterministic garbage collector.

>> Aonix PERC: A Java SE/RTSJ-compatible implementation with its own real-time, deterministic garbage collector. Aonix also has support for embedded devices with memory limitations, as well as systems with safety-critical requirements.

>> Fiji: A small-footprint Java implementation for embedded systems with deterministic garbage collection and support for safety-critical systems.

>> Javolution: A real-time Java library that provides a set of classes for deterministic execution and RTSJ support.

Again, true real-time Java development goes beyond the need for just real-time garbage collection. When choosing a real-time Java VM, whether it's RTSJ-compliant or not, be sure to choose one that guarantees your application will meet time-based requirements, with enough support to deterministically schedule your application's processing. Let's take a look at some areas real-time Java is being used today.

Business Success Cases

I've evaluated and deployed real-time Java in a wide range of applications. These include financial applications, such as trading engines, quote publishing, and news delivery; military systems, such as object tracking and flight control; telecommunication systems; and other specialized projects, including embedded systems, robotics, and embedded controllers.

Specific projects include a trading system developed at Reuters, embedded systems development at Perrone Robotics, a system for tracking space objects at ITT, flight systems at Boeing, and various military projects.

Most of these projects have been a big improvement over using specialized languages and programming environments that would have otherwise been required. Projects where real-time Java sometimes doesn't fit are ones where non-real-time requirements are mixed in, such as the need for high transaction rates and overall throughput. These are two areas that often require a trade-off to achieve predictable real-time behavior.

As tight time requirements become a greater part of enterprise computing, it's helpful to know that the same Java language and tooling used for developing standard applications can also be used to create deterministic, real-time computing solutions.

Eric J. Bruno is the author of "Real-Time Java Programming" and a blogger for Dr. Dobb's Journal. Write to us at iwletters@techweb.com.



Related Reading




Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

BYTE encourages readers to engage in spirited, healthy debate, including taking us to task. However, BYTE moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing/SPAM. BYTE further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.

Follow InformationWeek

By The Numbers

What Are Your Primary Concerns About Using Big Data Software?

Base: 417 respondents at organizations using or planning to deploy data analytics, BI or statistical analysis software
Data: InformationWeek 2013 Analytics, Business Intelligence and Information Management Survey of 541 business technology professionals, October 2012

What Do You Think?

What's your attitude about SQL analysis on top of Hadoop?
We want fast, standard SQL analysis capabilities on Hadoop ASAP
Hadoop is for unstructured data; SQL is for relational databases
We'll give SQL on Hadoop a try, but relational DBs will remain the mainstay
Given strong SQL support on Hadoop, we'd nix the data warehouse
We're not interested in Hadoop
No opinion



Related Content

From Our Sponsor

Five Big Data Challenges and How to Overcome Them with Visual Analytics

Five Big Data Challenges and How to Overcome Them with Visual Analytics

Business leaders often need a visual snapshot of data to quickly grasp and use it. This paper identifies five challenges in presenting data and how visual analytics can resolve them. Solutions are suggested to overcome the challenges of: speed, data clarity, data quality, displaying meaningful results, and dealing with outliers.

Game-Changing Analytics: How IT Executives Can Use Analytics to Create Innovation and Business Success

Game-Changing Analytics: How IT Executives Can Use Analytics to Create Innovation and Business Success

Today's competitive advantage requires a deeper understanding of your business, your market and your customers. As an IT executive, you can drive that knowledge transformation. In this white paper, learn how to make decisions as a strategic business leader and three steps to begin an analytics initiative within your enterprise.

Data Visualization Techniques: From Basics to Big Data with SAS Visual Analytics

Data Visualization Techniques: From Basics to Big Data with SAS Visual Analytics

High-performance data visualization turns sophisticated analyses into meaningful graphics, leading to faster and smarter decision making. In this white paper, learn how visual analytics can transform big data, with additional features such as real-time functionality, mobile compatibility, robust applications for technical groups and accessibility for nontechnical users.

Big Data: Lessons from the Leaders

Big Data: Lessons from the Leaders

Financial performance, competitive advantage, operational efficiency, strategic decision making - every business goal can extract value from big data, and the time for doubt or inaction has long passed. In this Economist Intelligence Unit report, in-depth interviews with data pioneers reveal the link between the effective use of big data and the bottom line among other results.

Decision-Driven Data Management: A Strategy for Better Decisions with Better Data

Decision-Driven Data Management: A Strategy for Better Decisions with Better Data

Which came first, the data or the decision? This white paper makes the case for having a decision in mind, then tailoring big data's volume, variety and velocity to achieve business results such as overcoming customer dissatisfaction or creating well-informed strategies in real time.

Informationweek Reports

Research: The Big Data Management Challenge

Research: The Big Data Management Challenge

The challenge of big data is real, but most organizations don't differentiate 'big data' from traditional data, and nearly 90% of respondents to our survey use conventional databases as the primary means of handling data. We'll help you understand what constitutes big data (it's not just size) and the numerous management challenges it poses.