A periodic real-time thread.

Java Primer
Through the Looking Glass: Java in Real-Time

Jim Mickelson and Marc R. Erickson
Listing 1. A periodic real-time thread.


import javax.realtime.*;
class PeriodicHelloThread extends RealtimeThread {
    public PeriodicHelloThread(PriorityParameters schP,
            PeriodicParameters relP) {
        super(schP, relP);
    }
    public void run() {
        System.out.println(“Hello Periodic World”);
        //This while loop will execute once per period
        while (waitForNextPeriod()) {  //wait until the start of the
            next period
            System.out.println(“Hello Again”);
        }
    }
    public static void main(String[] args) {
         PriorityParameters scheduling = new PriorityParameters(
            //scheduling parms
                RealtimeThread.RT_MAX_PRIORITY);  // realtime Thread
            priority

        PeriodicParameters release = new PeriodicParameters(
            //release parms
                new RelativeTime(0,0),      //start immediately, when
            schedulable
                new RelativeTime(5000,0),   //period: 5 sec
                new RelativeTime(20, 0),    //cost: 20 msec
                new RelativeTime(1000, 0),   //deadline: 1 sec
                null,                       //no cost overrun handler
                null);                      //no deadline miss handler

        PeriodicHelloThread rtThread = new PeriodicHelloThread
            (scheduling,release);
        rtThread.start();
    }
}

About the Authors


Marc R. Erickson is a project manager at Object Technology Inc., a subsidiary of IBM Corp., in Raleigh, NC. He can be contacted at mre@us.ibm.com.

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.