tandard Java has some deficiencies that make it less than ideal in the real-time world (see Sidebar 1. What Is Real-Time?
). For one, the garbage collector (an internal JVM thread that reclaims old objects to free space on the heap) can run at any time, for any length of time, thereby introducing latency and non-determinism to your application. However, the garbage collector (GC) is not the only culprit in a standard Java application. The just-in-time (JIT) compiler, which optimizes your Java code for the machine it's running on, can be invoked at any time, even for code that has previously been optimized (JIT-compiled).
Further, Java SE does not typically honor thread priorities as specified in your code. For instance, a thread that you create and specify to run at highest priority will likely not run at the highest priority in the system. Therefore, other application threads can preempt your Java application at any time, leading to further non-determinism. The Java Real-time System (Java RTS) from Sun is meant to resolve these issues.
Since 2006, Sun has been showing many large customers in the financial space (banks, brokerages, exchanges, and so on) how Java RTS can benefit their time-critical financial applications. With Java RTS, a customer can have real-time components and non-real-time components coexist and share data on a single system. The real-time components offer the added benefit of predictability and deterministic application behavior.
Version 2.0 of Java RTS contains a real-time garbage collector for bounded, sub-millisecond latencies, along with RTSJ-compliant programming models for bounded latencies at or below 20 microseconds (See Sidebar 2. Java RTS Virtual Machine for more details.). Java RTS 2.0 runs only on Solaris 10 systems with Intel, AMD, or SPARC processors, and it's fully Java 5 compliant. (For more on Java RTS version 2.0, see my previous DevX article on real-time Java, Go Inside the Java Real-time System.)
This article examines Java RTS in a use case that is common in Wall Street companies and financial institutions.
Java RTS and Financial Systems
Companies in the financial space, with systems that must respond to financial market events, have a need for real-time system behavior. Financial markets tend to move at a steady pace. Whether the pace is fast or slow, it's still crucial to respond to market events and trends within a bounded time frame to make money or to avoid losing it. A common Wall Street belief is that for every millisecond an investment bank can beat the market, it has the potential to earn an additional $100 million per year.
Both the data receivers (i.e., trading systems) and the data generators (i.e., market data feeds) consist of time-critical software systems that have real-time requirements. Unbounded latencies introduced by the Java garbage collector or by other activities represent significant financial loss to the companies operating these systems. Inversely, the elimination of these latencies and the added promise of determinism represent a significant competitive advantage.
Java RTS is meant to remove risk. To prove the benefit of Java RTS over standard Java in the real-time space, I've built a simulated limit/stop order trading system that works with both standard Java and Java RTS (See Sidebar 3. Limit/Stop Order Trades).