Real-Time Threads This section describes the two real-time thread classes.




Real-Time Threads

This section describes the two real-time thread classes. These classes:

The RealtimeThread class extends java.lang.Thread. The ReleaseParameters, SchedulingParameters, and MemoryParameters objects passed to the RealtimeThread constructor allow the temporal and processor demands of the thread to be communicated to the scheduler

The NoHeapRealtimeThread class extends RealtimeThread. A NoHeapRealtimeThread is not allowed to allocate or even reference objects from the Java heap, and can thus safely execute in preference to the garbage collector.


The RTSJ provides two types of objects which implement the Schedulable interface: real-time threads and asynchronous event handlers. This chapter defines the facilities that are available to real-time threads. In many cases these facilities are also available to asynchronous event handlers. In particular:

Where the semantics and requirements apply to both real-time threads and asynchronous event handlers, the term schedulable object will be used.

Semantics and Requirements for Real-time Threads

  1. Garbage collection executing in the context of a Java thread must not in itself block execution of a no-heap thread with a higher execution eligibility, however application locks work as specified even when the lock causes synchronization between a heap-using thread and a no-heap thread.
  2. Each real-time thread has an attribute which indicates whether an AsynchronouslyInterruptedException is pending. This attribute is set when a call to RealtimeThread.interrupt() is made on the associated real-time thread, and when an asynchronously interrupted exception's fire method is invoked between the time the real-time thread has entered that exception's doInterruptible method, and return from doInterruptible. (See the Asynchrony chapter.)
  3. A call to RealtimeThread.interrupt() generates the system's generic AsynchronouslyInterruptedException. (See the Asynchrony chapter.)
  4. The RealtimeThread.waitForNextPeriod and waitForNextPeriodInterruptible methods are for use by real-time threads that have periodic release parameters. In the absence of any deadline miss or cost overrun (or an interrupt in the case of waitForNextPeriodInterruptible) the methods return when the real-time thread's next period is due.
  5. In the presence of a cost overrun or a deadline miss, the behavior of  waitForNextPeriod is governed by the thread's scheduler.
  6. Instances of RealtimeThread that are created in scoped memory and instances of NoHeapRealtimeThread do not have conventional references to thread groups nor do thread groups have conventional references to these threads. For the purposes of this version of the specification those references are null.
  7. Real-time threads with null thread groups handle uncaught exceptions as if the thread used the uncaughtException method in ThreadGroup:


The Java platform's priority-preemptive dispatching model is very similar to the dispatching model found in the majority of commercial real-time operating systems.  However, the dispatching semantics were purposefully relaxed in order to allow execution on a wide variety of operating systems.  Thus, it is appropriate to specify real-time threads by extending java.lang.Thread.  The ReleaseParameters and MemoryParameters provided to the RealtimeThread constructor allow for a number of common real-time thread types, including periodic threads.

The NoHeapRealtimeThread class is provided in order to allow time-critical threads to execute in preference to the garbage collector given appropriate assignment of execution eligibility. The memory access and assignment semantics of the NoHeapRealtimeThread are designed to guarantee that the execution of such threads does not lead to an inconsistent heap state.