Real-time thread allocating objects.

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

Jim Mickelson and Marc R. Erickson
Listing 2. Real-time thread allocating objects.


import javax.realtime.*;
import java.util.Date;

class MemoryThread extends RealtimeThread {
    public MemoryThread(PriorityParameters priorityParms,
        MemoryArea memoryArea) {
        super(
            priorityParms,          //scheduling parms
            null,                   //release parms
            null,                   //memory parms
            memoryArea,             //default memory area
            null,                   //processing group
            null);                  //runnable code
    }
    public void run() {
        ImmortalMemory immortalMA = ImmortalMemory.instance();
        LTMemory linearMA = new LTMemory(1024, 1024);
        Date immortalDate;
        Date heapDate;
        try {
          //allocate from immortal memory
          immortalDate = (Date)immortalMA.newInstance(Class.
          forName(“Date”));
        } catch (Exception ex) {};
        //allocate from default Heap memory
        heapDate = new Date();
        linearMA.enter(new Runnable() {   //anonymous inner class
            public void run() {   //start scope for linearMA LTMemory
                  //allocate from scoped LT memory
                  Date ltMemoryDate = new Date();
            }   //end scope for linearMA LTMemory
        });
    }
    public static void main(String[] args) {
        MemoryThread memThread = new MemoryThread(
            new PriorityParameters(RealtimeThread.RT_MAX_PRIORITY),
              //max priority
            HeapMemory.instance()   //default heap memory area
        );
        memThread.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

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.