http://www.sun.com/ http://java.sun.com/ http://www.sun.com/javaone
JavaOne - Experiencing Java technology through education, industry, and community
2006 Conference
Topics
Sessions
   General Sessions
Hands-on Labs
Schedule
Schedule Builder
Register
Pavilion
   Cosponsors
   Exhibitors
   Media
   Presentation Theater
Java University
Daily Activities
Event Connect
Alumni
   Alumni FAQ
Multimedia Sessions
Community
JavaOne Online
Forums
java.sun.com
java.net
java.com
sun.com/developers
Java Wear & Books
Home

The 2006 JavaOne Conference Slot Car Racing Programming Challenge

by Janice J. Heiss

The 2006 JavaOne Conference Slot Car Racing Programming Challenge, designed by Sun Distinguished Engineer and Real-Time Specification for Java (RTSJ) (JSR-01) lead, Greg Bollella, is bringing real-time programming to attendees in a fun and exciting demo.

Here's the story: Standard 1/24 scale cars run around a track with 80 sensors spread along its length and with a power supply controlled by an A/D converter driven from a workstation. The sensors are simple photocell gates similar to those that detect paper moving through a printer. Normally, the cars are driven by a small hand-held controller that competitors press to send voltage to speed up the car.

Contestants are challenged to write RTSJ code that controls the car while making it go as fast as possible without flying off the track. The Real-Time Java program senses the track position of a slot car and sets the voltage to the track — and thus the speed of the car. The program detects whether or not the car is over a sensor, but it doesn't know which sensor, since all the sensors are effectively merged together. Therefore, developers who enter the Challenge have to write a polling loop that gathers the sensor data and keeps track of where the car is based on the sensor map. Then the program gives the car the appropriate voltage that speeds it up on the straight-aways and slows it down on the curves. Contestants will write the code in the labs and bring it to the track where it will be run on a workstation. The top three finishers receive prizes and will face off live during James Gosling's keynote on Friday morning.

Runs are conducted on a first-come, first-served basis and contestants can have as many runs as time permits. For example, those with wireless laptops can return to the end of the line when their run is over, enter coding changes, and wait their turn. If a car crashes, the track operator will stop the program and give the car a time of 1,000 seconds, effectively removing any possibility of success. James Gosling, who has made contributions to RTSJ, observed that, "It's remarkably easy to send the car flying off the corners."

The finished slot car track
The finished slot car track

Dispelling Real-Time Java FUD

In addition to being fun, the Challenge is intended to dispel Real-Time Java FUD, especially the idea that it is hard to program in RTSJ. As Bollella puts it, "The Slot Car Challenge will prove that anyone can program with RTSJ. If a developer gets the car to go around the track without missing any of the sensors, they will have written hard real-time code in the most rigorous sense of hard real-time. I want to get the message across to the developer community: Programming in Real-Time Java isn't rocket science. It's more like bicycle science."

"Hard" real-time logic refers to responses to real-time events that must never fail to occur within the set period — if the logic fails with the slot cars, they crash. "Soft" real-time is suitable for systems where the consequences of missing a deadline are allowed, but allowed in a predefined, understood manner. Java technology has, for the most part, been used with non-real-time logic in the past.

Considerable confusion exists about Real-Time Java, starting with the name itself. "Real-time" is often mistaken to mean "real fast," whereas in fact it means to "respond within a reliable and predictable time." It's less about speed and more about absolute reliability.

slot car
Slot Car

In engineering RTSJ, Bollella's group has taken a highly-engineered and optimized system platform, the HotSpot JVM, and modified it so that it not only retains its value for non-real-time programs, but can engage in real-time programming of physical systems with relative ease. RTSJ, the only real-time Java technology, is 100% Java and was started in 1998 and developed by a team of experts from several diverse communities: RT-scheduling, embedded systems design, Ada design, Java design, embedded processor design, real-time systems design, academia, RTOS design, and others.

Real-time Java has proved itself in diverse ways. The military has employed it to detect inbound missiles. Telecommunications infrastructure provides excellent call handling, but occasionally a line is broken and must be addressed within a narrow time slice where RTSJ proves its mettle. In finance, where the value of a large position can change by a million dollars in a second, and stock traders describe themselves as in a technology arms race with the competition, Real-Time Java has been effective. It has also been used in industrial automation and the automotive industry.

Dangling by a Thread

Threading is of paramount importance to RTSJ and two new thread types have been created.

The javax.realtime.RealtimeThread:

  • Is for 'soft' real-time
  • Can use the Heap, Immortal, and ScopedMemory
  • Programs just like a regular Java thread
  • Has all libraries available
  • Depends on the use of the real-time GC

The javax.realtime.NoHeapRealtime Thread:

  • Is for 'hard' real-time
  • Can use ONLY Immortal, and ScopedMemory
  • Needs care when using library methods
  • Is necessary for only very small, well-defined logic
  • For application managed real-time garbage collection

In addition to the myth that RTSJ is hard or weird other myths persist: It's a myth that most libraries don't work in a NoHeap context — most work fine.

Converting to Real-Time Java

Converting a 'normal' Java program to a Real-Time Java program is surprisingly easy and essentially involves a syntax change.

For starters, replace:

Thread T = new java.lang.Thread();

With:

RealtimeThread RT = new javax.realtime.RealtimeThread();

And you get industrial-strength, real-time garbage collection, plus 28+ priorities that actually work, priority inheritance protocol, physical memory, and more.

For more details check out TS-1904, "Real-Time Java Technology: Why It Matters to You and What You Should Do About It!" with Greg Bollella and Dave Hofert of Sun, plus Paul Perrone of Perrone Robotics, Ed Pla of Boeing and David Atkins of PrismTech, on Friday, May 19, from 1:15-2:15.


See Also


 Back to top


Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.