Download presentation
Presentation is loading. Please wait.
Published byEthelbert Fleming Modified over 9 years ago
1
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and Real Time programming The Real-time Specification for Java
2
Instructore: Tasneem Darwish2 Time Values and Clocks Java supports the notion of a wall clock (calendar time). The Date class is intended to reflect UTC (Universal Time Coordinated), however, accuracy depends on the host system. The RTSJ introduces clocks with high-resolution time types. The associated classes are illustrated in the figure.
3
Instructore: Tasneem Darwish3 Time Values and Clocks HighResolutionTime encapsulates time values with nanosecond and an associated clock. A value is represented by a 64-bits millisecond and a 32-bits nanosecond component. There are methods to read, write and compare time values, as well as methods to get and set the clock. The class is an abstract class that has three subclasses: one that represents relative time, one that represents absolute time, and one that represents "rational" time.
4
Instructore: Tasneem Darwish4 Time Values and Clocks Relative time is a duration measured by a particular clock. Absolute time is actually expressed as a time relative to some epoch. This epoch depends on the associated clock. Rational time is a relative-time type, which has an associated frequency. It is used to represent the rate at which certain events occur (for example, periodic thread execution).
5
Instructore: Tasneem Darwish5 Time Values and Clocks The RTSJ Clock class defines the abstract class from which all clocks are derived. The specification allows many different types of clocks; for example, there could be a CPU execution-time clock (although this is not required by the RTSJ). There is always one real-time clock that advances monotonically. A static method getRealtimeClock allows this clock to be obtained. Countdown clocks are called timers by the RTSJ
6
Instructore: Tasneem Darwish6 Schedulable Objects and Scheduling Java allows each thread to have a priority that can be used by the JVM when allocating processing resources. However, Java offers no guarantees that the highest priority runnable thread will be the one executing at any point in time. This is because a JVM may be relying on a host operating system to support its threads. Some of these systems may not support preemptive priority-based scheduling.
7
Instructore: Tasneem Darwish7 Schedulable Objects and Scheduling Furthermore, Java only defines 10 priority levels, and an implementation is free to map these priorities onto a more restricted host operating system's priority range if necessary The RTSJ attacks these problems on several fronts. Firstly, it generalizes the entities that can be scheduled away from threads toward the notion of schedulable objects.
8
Instructore: Tasneem Darwish8 Schedulable Objects and Scheduling A schedulable object is one that implements the Schedulable interface. Each schedulable object must also indicate its specific: 1.release requirement (that is, when it should become runnable), 2.memory requirements (for example, the rate at which it will allocate memory on the heap), 3.scheduling requirements (for example, the priority at which it should be scheduled).
9
Instructore: Tasneem Darwish9 Parameters affecting scheduling Release requirements are specified via the ReleaseParameters class hierarchy. Scheduling theories often identify three types of releases: 1.periodic (released on a regular basis), 2.aperiodic (released at random) and 3.sporadic (released irregularly, but with a minimum time between each release). These are represented by the PeriodicParameters, AperiodicParameters and SporadicParameters classes respectively.
10
Instructore: Tasneem Darwish10 Parameters affecting scheduling All release parameter classes encapsulate a cost and a deadline (relative time) value. The cost is the maximum amount of CPU time (execution time) needed to execute the associated schedulable object every time it is released. The deadline is the time at which the object must have finished executing the current release; it is specified relative to the time the object was released.
11
Instructore: Tasneem Darwish11 Parameters affecting scheduling Scheduling parameters are used by a scheduler to determine which object is currently the most eligible for execution. The abstract class SchedulingParameters provides the root class. ImportanceParameters allow an additional numerical scheduling metric to be assigned; it is a subclass of the PriorityParameters class.
12
Instructore: Tasneem Darwish12 Schedulers The scheduler is responsible for scheduling its associated schedulable objects. The RTSJ is silent on how many schedulers might exist within a single real-time JVM but typically only a single scheduler will be present. Although RTSJ explicitly supports priority-based scheduling via the PriorityScheduler, it acknowledges that an implementation might provide other schedulers. Consequently, Scheduler is an abstract class with PriorityScheduler a defined subclass.
13
Instructore: Tasneem Darwish13 Schedulers
14
Instructore: Tasneem Darwish14 Meeting deadlines Once a system accepts that schedulable objects have deadlines and a cost associated with their execution, there is an obligation on the system to undertake the following activities: provide a means by which it is possible to predict whether a set of application objects will meet their deadlines, and provide mechanisms whereby the system can report that an application object has missed its deadline, consumed more resources than indicated by the cost value.
15
Instructore: Tasneem Darwish15 Real-time Threads One type of schedulable object is a real-time thread represented by the RealtimeThread class. This is an extension of the Java Thread class, which also implements the Schedulable interface. A real-time thread's parameters are illustrated in the figure.
16
Instructore: Tasneem Darwish16 Real-time Threads A periodic real-time thread is a real-time thread that has periodic release parameters. Similarly, an aperiodic (or sporadic) real-time thread is one that has aperiodic (or sporadic) release parameters. A NoHeapRealtimeThread is one that guarantees not to create or reference any objects on the heap. Hence, its execution is totally independent of the garbage collector
17
Instructore: Tasneem Darwish17 Asynchronous Event Handling and Timers Threads and real-time threads are the appropriate abstractions to use when representing concurrent activities. However, it is also often necessary to respond to events that happen asynchronously to a thread's activity. These events may be happenings in the environment of an embedded system or notifications received from internal activities within the program.
18
Instructore: Tasneem Darwish18 Asynchronous Event Handling and Timers It is always possible to have extra threads that wait for these events, but this is inefficient and may result in an explosion of the number of threads in a program. In Java, standard classes can be programmed that multiplex events onto a single thread that handles them in a particular order.
19
Instructore: Tasneem Darwish19 Asynchronous Event Handling and Timers From a real-time perspective, events may require their handlers to respond within deadlines. Hence, more control is needed over the order in which events are handled. The RTSJ, therefore, generalizes Java event handlers to be schedulable entities.
20
Instructore: Tasneem Darwish20 Asynchronous Event Handling and Timers The RTSJ, therefore, generalizes Java event handlers to be schedulable entities. Like real-time threads, the schedulable entities have a variety of parameters illustrated in the figure.
21
Instructore: Tasneem Darwish21 Asynchronous Transfer of Control Asynchronous events allow the program to respond in a timely fashion to a condition that has been detected by the program or the environment. However, they do not allow a particular schedulable object to be directly informed.
22
Instructore: Tasneem Darwish22 Asynchronous Transfer of Control In many applications, the only form of asynchronous notification that a real-time thread needs is a request for it to terminate itself. instead what is required is for the schedulable object to stop what it is currently doing and begin executing an alternative algorithm.
23
Instructore: Tasneem Darwish23 Asynchronous Transfer of Control In Java, it is the interrupt mechanism that attempts to provide a limited form of asynchronous notification. unfortunately, the mechanism is synchronous and does not support timely response to the "interrupt". Instead, a running thread has to poll for notification. This delay is deemed unacceptable for real-time systems.
24
Instructore: Tasneem Darwish24 Asynchronous Transfer of Control For the previous reasons, the RTSJ provides an alternative approach for interrupting a schedulable object, using asynchronous transfer of control (ATC). The ATC model is based on the following principles: 1.A schedulable object must explicitly indicate that it is prepared to allow an ATC to be delivered. 2.The execution of synchronized methods and statements always defers the delivery of an ATC. 3.ATCs have termination semantics; this means that the schedulable object does not resume execution at the point in its code where the ATC was delivered.
25
Instructore: Tasneem Darwish25 Asynchronous Transfer of Control The RTSJ ATC model is integrated with the Java exception handling facility. An AsynchronouslyInterruptedException (AIE) class defines the ATC event. Every method that is prepared to allow the delivery of an AIE must indicate so via a throws AsynchronouslyInterruptedException in its declaration.
26
Instructore: Tasneem Darwish26 Asynchronous Transfer of Control ATCs are deferred until the thread is executing within such a method. The Interruptible interface provides the link between the AIE class and the object executing an interruptible method. A subclass of AIE, called Timed, allows an ATC to be generated at a point in time (absolute or relative). The ATC facilities also allow real-time threads to be terminated in a controlled and safe manner.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.