Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 G53SRP: Clocks and Times in RTSJ Chris Greenhalgh School of Computer Science.

Similar presentations


Presentation on theme: "11 G53SRP: Clocks and Times in RTSJ Chris Greenhalgh School of Computer Science."— Presentation transcript:

1 11 G53SRP: Clocks and Times in RTSJ Chris Greenhalgh School of Computer Science

2 22 Contents OverviewOverview Time classesTime classes –HighResolutionTime, AbsoluteTime, RelativeTime Clock classClock class ExampleExample SummarySummary Book: Wellings ch. 9Book: Wellings ch. 9

3 3 Class Overview 3 > javax.realtime. HighResolutionTime javax.realtime. AbsoluteTime javax.realtime. RelativeTime extends javax.realtime. Clock has javax.realtime. RationalTime extends Deprecated (do not use)

4 4 HighResolutionTime class package javax.realtime; public abstract class HighResolutionTime { // nano-second resolution times public long getMilliseconds(); public int getNanoseconds(); public void set(long millis, int nanos); public Clock getClock(); // various utility/conversion methods … // high-res wait public static waitForObject(Object target, HighResolutionTime time) throws InterruptedException ; } Every time is based on a clock (it came from)

5 5 AbsoluteTime Class package javax.realtime; public class AbsoluteTime extends HighResolutionTime { // cons (also others) public AbsoluteTime(long millis, int nanos); // various utility conversions including… public AbsoluteTime add(RelativeTime time); public RelativeTime subtract(AbsoluteTime time); public AbsoluteTime subtract(RelativeTime time); … } Time is offset from clock-specific EpochTime is offset from clock-specific Epoch –Default clock Epoch is midnight 1 st January 1970 GMT

6 6 RelativeTime class package javax.realtime; public class RelativeTime extends HighResolutionTime { // cons (also others) public RelativeTime(long millis, int nanos); // various utility conversions including… public RelativeTime add(RelativeTime time); public RelativeTime subtract(RelativeTime time); … } Note: still based on a Clock, e.g. for resolution (and accuracy)

7 7 Clock class package javax.realtime; public abstract class Clock { // standard system realtime clock public static Clock getRealtimeClock(); public AbsoluteTime getTime(); public RelativeTime getResolution(); // offset of this clock vs Epoch public RelativeTime getEpochOffset(); … } Note: may be other clocks without date, e.g. timer from power-on of system. If so, this throws UnsupportedOperationException

8 8 E.g. RTClock.java … Clock clock = Clock.getRealtimeClock(); AbsoluteTime time = clock.getTime(); AbsoluteTime newTime = clock.getTime(); RelativeTime elapsed = newTime.subtract(time); RelativeTime delay = new RelativeTime(1000,0); AbsoluteTime delayTime = newTime.add(delay); …

9 9 E.g. RTSleep.java … Clock clock = Clock.getRealtimeClock(); AbsoluteTime time = clock.getTime(); RelativeTime delay = new RelativeTime(1000,0); AbsoluteTime delayTime = time.add(delay); RealtimeThread.sleep(delay); RealtimeThread.sleep(delayTime); … Relative sleep i.e. delay ms/ns Absolute sleep i.e. until delayTime

10 10 Summary RTSJ supports nanosecond-resolution times – –HighResolutionTime – –(but Clocks probably won’t be nanosecond granularity) Can be used for – –Wait variant ( HighResolutionTime.waitForObject ) – –Sleep variant ( RealtimeThread.sleep ) – –Other time specifications (e.g. ReleaseProperties – later) Distinguishes relative and absolute times – –AbsoluteTime & RelativeTime – –Includes various utility manipulation operations Supports at least one real-time clock – –Clock.getRealtimeClock() – –May support more


Download ppt "11 G53SRP: Clocks and Times in RTSJ Chris Greenhalgh School of Computer Science."

Similar presentations


Ads by Google