RTSJ Hello World
Working with the TimeSys reference implementation of the RTSJ installed on a Linux system in /usr/local/timesys and with the Sun JDK tools, we show here a step-by-step procedure for creating and running a hello world program for real time.
Hello world doesn't have significant timeliness constraints, so Example 81 will just run the standard hello world in a real-time thread.
Example 81 RT hello world program
import javax.realtime.*; public class Hello1 { public static void main(String [] args){ RealtimeThread rt= new RealtimeThread(){ public void run() { System.out.println("Hello RT world"); } }; if(!rt.getScheduler().isFeasible()) System.out.println("Printing hello is not feasible"); else rt.start(); } }
The program shown in Example 81 is a complete program. Since it prints "Hello RT world" from a real-time thread, that part of its execution can take advantage of priority inheritance and strictly defined, fixed-priority, preemptive scheduling. Those scheduling properties do not make much difference to the output of one short string, but they are there.
To test the program:
If you are developing from the command line, you might use a command like this to compile Hello1:
javac -classpath /usr/local/timesys/rtsj-ri/lib/foundation.jar Hello1.java
If the real-time JVM is on your execution path and the classpath is set to your real-time Java class libraries, a simple command line will run the program:
tjvm Hello1
More likely, you'll need a command line like this:
tjvm -Djava.class.path=/home/dibble/javaprogs/hello1 -Xbootclasspath=/usr/local/timesys/rtsj-ri/lib/foundation.jar Hello1
The output will be:
Hello RT world!