1 / 67

Real-Time Java * Programming

Real-Time Java * Programming. Christopher D. Gill cdgill@cs.wustl.edu Center for Distributed Object Computing Department of Computer Science Washington University, St. Louis http://www.cs.wustl.edu/~cdgill/RTSJ/COOTS01_M4.ppt COOTS 2001 Tutorial M4 Monday, January 29, 2001.

myolanda
Download Presentation

Real-Time Java * Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Real-Time Java* Programming Christopher D. Gill cdgill@cs.wustl.edu Center for Distributed Object Computing Department of Computer Science Washington University, St. Louis http://www.cs.wustl.edu/~cdgill/RTSJ/COOTS01_M4.ppt COOTS 2001 Tutorial M4 Monday, January 29, 2001 *JavaTM is a registered trademark of Sun Microsystems

  2. Real-Time Java Programming Tutorial Objectives • Provide an overview of real-time programming issues • Describe a motivating real-time programming example • An on-line stock market analysis tool • Exhibits canonical requirements and issues common to other classes of real-time systems • Show through incremental evolution of the example • How real-time programming issues can arise in a JavaTM (Java) programming environment • How features of the Real-Time Specification for JavaTM (RTSJ) can be applied to resolve these issues

  3. Real-Time Java Programming Example: Stock Market Analysis Tool • Performs automated decision aiding for stock trading • Inputs arrive from real-time data streams • May run queries against on-line databases • Sends alerts to human operator and/or other automated systems with specific recommendations (e.g., sell, buy, limit order, short, call, put) • Timeliness of outputs is crucial • A functionally correct output sent too late can be worse than no output at all • Several application layers compete in real-time for system resources (i.e., CPU, memory)

  4. Real-Time Java Programming Example: Stock Market Analysis Tool • Inputs arrive in real-time from data streams • Real-time (seconds) arrival of data events • One feed per market • May run queries on-line tables and databases: differences in latency and latency jitter • Analyst reports • Market histories • Sector P/E tables DataFeed NYSEFeed NasdaqFeed DataStore NYSEStore NasdaqStore ResearchStore

  5. Real-Time Java Programming Example: Stock Market Analysis Tool • Sends recommendations as alerts to: • Human operators • Automated systems • Documented quality of information is key • Decision path, triggers • Additional info, links • Timeliness constraints must also be met • Incremental addition, refinement is useful * Annotation Alert MarketOrder Option Buy Sell Call Put

  6. Real-Time Java Programming Example: Stock Market Analysis Tool 1+ AnalysisFilter AnalysisPipeline 1+ SectorPE PortfolioBalance Composite • Input events pass through an analysis pipeline • Each analysis filter handles the data and news events in which it is interested, may search databases • May attach additional information to event and pass it on or consume it, and/or produce alerts • Composites combine other analysis filters

  7. Real-Time Java Programming Example: Roadmap AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio DataFeedEvent Annotation AnnotationList DataFeed Alert NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  8. Real-Time Java Programming Example: Stock Market Analysis Tool // Input Event Streams Code public class DataFeedEvent { private float bid; private float ask; private float change; private long volume; // ... public DataFeedEvent (float b, float a, float c, long v) {bid = b; ask = a; change = c; volume = v;} public float getBid () {return bid;} public float getAsk () {return ask;} public float getChange () {return change;} public long getVolume () {return volume;} // ... } market order 90 seconds data event Market data feed

  9. Real-Time Java Programming Example: Stock Market Analysis Tool // Input Event Streams Code, Continued public abstract class DataFeed { public abstract DataFeedEvent pullDataFeedEvent (); } public class NasdaqDataFeed extends DataFeed { // low-ish latency public DataFeedEvent pullDataFeedEvent () { return pullNasdaqDataFeedEvent (); } protected DataFeedEvent pullNasdaqDataFeedEvent () { float bid = 0.0F; float ask = 0.0F; float chg = 0.0F; long vol = 0; // read data from socket, etc... return new DataFeedEvent (bid, ask, chg, vol); } } /* ... Other DataFeed Classes ... */ • Separate data feed for each market • Low latency to pull an event from a market data feed

  10. Real-Time Java Programming Example: Roadmap AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio Annotation AnnotationList Alert DataFeedEvent DataFeed NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  11. Real-Time Java Programming Example: Stock Market Analysis Tool // Alerts Code public abstract class Annotation { /* ... */ } public class AnnotationList { private java.util.Vector alist; // list of annotations public void addSorted (Annotation a) { /* ... */ } } public abstract class Alert { private AnnotationList anotes; private DataFeedEvent trigger; Alert (DataFeedEvent dfe) {anotes = new AnnotationList (); trigger = dfe;} public DataFeedEvent getTrigger () {return trigger;} public void addAnnotation (Annotation a) { anotes.addSorted (a); } public Annotation nextAnnotation (boolean restart) { /* move to next annotation in list, return it ... */ } } Alert trigger annotations

  12. Real-Time Java Programming Example: Stock Market Analysis Tool // Alerts Code, Continued public abstract class MarketOrderAlert extends Alert { private float orderPrice; private String symbol; public MarketOrderAlert (DataFeedEvent dfe, float op, String s) {super (dfe); orderPrice = op; symbol = s;} protected String getSymbol () {return symbol;} protected float getOrderPrice () {return orderPrice;} } /* ... Similarly, for OptionAlert and its derived classes ... */ public class BuyAlert extends MarketOrderAlert { public BuyAlert (DataFeedEvent dfe, float op, String s) {super (dfe, op, s);} float getBuyPrice () { return super.getOrderPrice (); } } /* ... Similarly for SellAlert, Other Alert Classes ... */

  13. Real-Time Java Programming Example: Stock Market Analysis Tool // Data Store Query Code public class NasdaqAnnotation extends Annotation { private float sectorAvgEarnings; private float sectorPERatio; public NasdaqAnnotation (float e, float r) {sectorAvgEarnings = e; sectorPERatio = r;} public float getSectorAvgEarnings () {return sectorAvgEarnings;} public float getSectorPERatio () {return sectorPERatio;} }/* ... Other Annotation Classes */ public class ResearchAnnotation extends Annotation { // URLs for research reports private java.util.Vector research_reports; public void addReport (java.net.URL u) {reports.add (u);} public java.net.URL nextReport (boolean restart) { /* ... */ } }/* ... Other Annotation Classes */ annotations P/E URL sector analysis table research reports

  14. Real-Time Java Programming Example: Roadmap AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio Annotation AnnotationList Alert DataFeedEvent DataFeed NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  15. Real-Time Java Programming Example: Stock Market Analysis Tool // Data Store Query Code, Continued public abstract class DataStore { public abstract void annotateAlert (Alert a);} public class NasdaqStore extends DataStore { public float getPE (String symbol, boolean sector) {/* medium duration */} public float getEarnings (String symbol) {/*...*/} public void annotateAlert (Alert a) { addNasdaqAnnotation (a); /* ... */ } protected void addNasdaqAnnotation (Alert a) { float e = 0.0F; float r = 0.0F; // compute PE and Earnings averages for the sector a.addAnnotation (new NasdaqAnnotation (e, r)); } } annotations P/E sector analysis table analysis query Nasdaq market history database

  16. Real-Time Java Programming Example: Stock Market Analysis Tool // Data Store Query Code, Continued public class ResearchStore extends DataStore { public void annotateAlert (Alert a) { addResearchAnnotation (a);} protected void addResearchAnnotation (Alert a) { // long duration: guided // search for research // reports, adding URLS // for relevant analyst // research reports to // the annotation // (ordered by relevance // & confidence factors) // add annotation to alert a.addAnnotation (new ResearchAnnotation ()); } } /* ... Other DataStore Classes ... */ annotations URL report index search agent hyper-linked research reports

  17. Real-Time Java Programming Example: Roadmap AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio Annotation AnnotationList Alert DataFeedEvent DataFeed NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  18. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Filter Code public class AlertList {// Alerts raised so far private java.util.Vector alerts; public void addAlert (Alert a) {alerts.add (a);} public Alert nextReport (boolean restart) { /* ... */ } public void reset () { alerts.clear ();} } public abstract class AnalysisFilter {public abstract boolean handleDataEvent (DataFeedEvent d, AlertList a); // ... } alert list Analysis filter data event data feed

  19. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Filter Code, Continued public class CompositeFilter extends AnalysisFilter { // the composed filters private java.util.Vector filters; public void addFilter (AnalysisFilter af) { filters.add (af); } public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; for (int i = 0; !consumed && i < filters.size (); ++i) { consumed = ((AnalysisFilter) filters.get(i)).handleDataEvent (dfe, al); } return consumed; } } data event Composite Filter

  20. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Filter Code, Continued public class SectorPEFilter extends AnalysisFilter { private NasdaqStore nh; private ResearchStore rr; public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; // See if event is of interest, // compare its PE to the avg for // its sector, look at existing // alerts, possibly generate // new ones annotated with // relevant research reports rr.annotateAlert (alert) return consumed; } } data event Sector P/E Filter sector analysis table research reports

  21. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Filter Code, Continued public class Portfolio { public float projectRiskDelta (DataFeedEvent d) {/*...*/} public float projectGainDelta (DataFeedEvent d) {/*...*/} } public class PortfolioBalanceFilter extends AnalysisFilter { protected Portfolio p; public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; // issue/remove alerts based on // data feed event and projected // risk/gain to portfolio goals return consumed; } } alert list data event Portfolio Balance Filter risk profile goals

  22. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Pipeline Code public class AnalysisPipeline { private CompositeFilter cf; private DataFeed df; private AlertList al; public void addFilter (AnalysisFilter af) {cf.addFilter (af);} public void sendAlerts () {/* Send all alerts, reset list */} public void run () { for (;;) { DataFeedEvent dfe = df.pullDataFeedEvent (); cf.handleDataEvent (dfe, al); // possibly long latency sendAlerts (); /* latency depends on alert count */} } } alert list send alerts data event Operator Filter Pipeline

  23. Real-Time Java Programming Example: Stock Market Analysis Tool // Analysis Tool Code public class AnalysisTool { public static void main (String [] args) { AnalysisPipeline ap = new AnalysisPipeline (); ap.addFilter (new PortfolioBalanceFilter ()); ap.addFilter (new SectorPEFilter ()); ap.run (); // run the pipeline } } alert list send alerts market order data event data feed Market

  24. Real-Time Java Programming Review: Roadmap AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio DataFeedEvent Annotation AnnotationList DataFeed Alert NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  25. AnalysisTool ResearchAnnotation ResearchStore Latency: Medium High Low Real-Time Java Programming Example: Time Scales AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio DataFeedEvent Annotation AnnotationList DataFeed Alert NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  26. Real-Time Java Programming Java Real-Time Issues • Existing JavaTM facilities take us several important steps in the direction of real-time application behavior • Threads • Liveness (what and how much happens) • Threads are used to decouple activity time scales • Synchronization • Safety (nothing “unsafe” happens) • Careful application of monitors can preserve liveness • We’ll start in a bottom-up liveness-first design mode, using thread adapters (Lea, “Concurrent Programming in JavaTM”)

  27. Real-Time Java Programming Java: Threading Issues • Separate threads of execution are useful to improve liveness by doing the following concurrently: • Getting and handling market data events • Medium latency • Searching stores to add annotations • High latency • Issuing alerts • Low latency // Analysis Tool Code, Revisited // Separate high latency activity public class StoreThreadAdapter implements Runnable { private DataStore store; private Alert alert; public StoreThreadAdapter (DataStore ds, Alert a) { store = ds; alert = a;} public void run () { store.annotateAlert (alert); } }

  28. Real-Time Java Programming Java: Threading Issues // Analysis Filter Code, Revisited public class SectorPEFilter extends AnalysisFilter { private NasdaqStore nh; private ResearchStore rr; public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; // possibly generate new alerts ... // ... annotated with relevant research reports... Thread annotationThread = new Thread (new StoreThreadAdapter (rr, alert)); annotationThread.setPriority (Thread.MIN_PRIORITY); annotationThread.start (); return consumed; } }

  29. Real-Time Java Programming Java: Threading Issues // Analysis Tool Code, Revisited // Separate low latency activity public class AlertThreadAdapter implements Runnable { private AnalysisPipeline pipeline; private long timeout; public AlertThreadAdapter (AnalysisPipeline ap, long t) { pipeline = ap; timeout = t;} public void run () { for (;;) // in reality, could use more sophisticated { // loop control e.g., wait, notifyAll, etc. try { Thread.sleep (timeout); pipeline.sendAlerts (); } catch (java.lang.InterruptedException e) {/* ... */} } } }

  30. Real-Time Java Programming Java: Threading Issues // Analysis Pipeline Code, Revisited // Separate medium latency activity public class AnalysisPipeline { private CompositeFilter cf; // filters in the pipeline private DataFeed df; // paced data event feed private AlertList al; // list of alerts public void addFilter (AnalysisFilter af) {cf.addFilter (af);} public void sendAlerts () {/* Send all alerts in the list, reset alert list */} public void run () { for (;;) { DataFeedEvent dfe = df.pullDataFeedEvent (); cf.handleDataEvent (dfe, al); // possibly long latency } } }

  31. Real-Time Java Programming Java: Threading Issues // Analysis Tool Code, Revisited public class AnalysisTool { public static void main (String [] args) { AnalysisPipeline ap = new AnalysisPipeline (); ap.addFilter (new PortfolioBalanceFilter ()); ap.addFilter (new SectorPEFilter ()); Thread alertThread = new Thread (new AlertThreadAdapter (ap, 1000)); alertThread.setPriority (Thread.MAX_PRIORITY); alertThread.start (); ap.run (); // run pipeline in the current thread } }

  32. Real-Time Java Programming Java: Synchronization Issues • But, before we go further addressing liveness issues, need to address concurrency safety • Shift to top-down safety-first design mode, using fine-grain synchronization (Lea, “Concurrent Programming in JavaTM”) • We’ll combine two styles: block and method synchronization // Concurrency safety additions // using method synchronization public abstract class Alert { /* ... */ public synchronized void addAnnotation (Annotation a) {/* ...*/} public synchronized Annotation nextAnnotation (boolean restart) {/*...*/} }

  33. Real-Time Java Programming Java: Synchronization Issues // Concurrency safety additions using block synchronization public class AnalysisPipeline { /* ... */ protected void sendAlerts () { synchronized (al) {/* Send all the alerts in the list, reset alert list */} } public void run () { for (;;) { DataFeedEvent dfe = df.pullDataFeedEvent (); // spawns separate threads for long latency activities cf.handleDataEvent (dfe, al); } }

  34. Real-Time Java Programming Java: Synchronization Issues // Concurrency safety additions using block synchronization public class PortfolioBalanceFilter extends AnalysisFilter { protected Portfolio p; public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; synchronized (al) { /* add alerts based on data feed event and the projected risk and gain changes to portfolio */ } return consumed; } }

  35. Real-Time Java Programming Java: Synchronization Issues // Concurrency safety additions using block synchronization public class SectorPEFilter extends AnalysisFilter { private NasdaqStore nh; private ResearchStore rr; public boolean handleDataEvent (DataFeedEvent dfe, AlertList al) { boolean consumed = false; /* compare PE to the average for its sector */ synchronized (al) { /* look at existing alerts*/ } /* possibly generate new ones, annotated in a separate thread with relevant research reports... */ synchronized (al) { /* add any new alerts to the list */ } return consumed; } }

  36. medium latency low latency AlertList AnnotationList high latency Synchronization points: Real-Time Java Programming Threads and Synch Points AnalysisTool AnalysisPipeline AnalysisFilter AlertList CompositeFilter SectorPEFilter PortfolioBalanceFilter Portfolio DataFeedEvent Annotation AnnotationList DataFeed Alert NasdaqDataFeed ResearchAnnotation MarketOrderAlert OptionAlert DataStore NasdaqAnnotation CallAlert PutAlert NasdaqStore ResearchStore BuyAlert SellAlert

  37. Real-Time Java Programming The RTSJ and Real-Time Issues • Threads (revisited) • Release characteristics & failures • Scheduling • Synchronization (revisited) • Time and timers • Asynchronous event handling • Memory management • Asynchronous transfer of control • Exceptions • System-level options

  38. Real-Time Java Programming RT Issues: Threads • Multi-threading is useful to decouple different activities • Active objects, request queues, synch/asynch • However, work in different threads competes for CPU time and memory resources • Must ensure resource usage by non-critical activities does not interfere with needs of critical activities

  39. Real-Time Java Programming RTSJ: Threading Issues // Solution: real-time threads AlertThreadAdapter alertAdapter = new AlertThreadAdapter (ap, 1000); javax.realtime.RealtimeThread alertThread = new javax.realtime.RealtimeThread (alertAdapter); javax.realtime.RealtimeThread pipelineThread = new javax.realtime.RealtimeThread (ap); alertThread.start (); pipelineThread.start (); • Threads compete for time on the CPU • Some activities are higher priority than others • Java thread priorities take us a step in the right direction, but… • garbage collector thread priority and preemption issues • Non-RT priority uniqueness is not ensured

  40. Real-Time Java Programming RTSJ: Threading Issues // To run the pipeline in a Realtime thread, it could just implement Runnable: for AnalysisPipeline this is not very invasive so we’ll skip writing a separate adapter public class AnalysisPipeline { /* ... */ protected void sendAlerts () { synchronized (al) {/* Send all the alerts in the list, reset alert list */} } public void run () { for (;;) { DataFeedEvent dfe = df.pullDataFeedEvent (); // spawns separate threads for long latency activities cf.handleDataEvent (dfe, al); } } implements Runnable

  41. execution cost period deadline minimum inter-arrival spacing Real-Time Java Programming RT Issues: Release Characteristics • To know whether threads will interfere, need to characterize their temporal behavior • Need descriptors with key temporal attributes • E.g., execution cost, deadline • Can abstract out separate descriptors for canonical behavioral classes • I.e., periodic, aperiodic, sporadic Time

  42. Real-Time Java Programming RTSJ: Release Characteristics Issues • While threading allows priority partitioning, specific information and/or constraints on threads are needed • Must ensure sufficient resources are available and correctly managed for desired behavior javax.realtime.RelativeTime cost = new javax.realtime.RelativeTime (100, 0); javax.realtime.RelativeTime period = new javax.realtime.RelativeTime (1000, 0); javax.realtime.PeriodicParameters pp = new javax.realtime.PeriodicParameters ( null, // start immediately, period, cost, null, // deadline = period end null, null); alertThread.setReleaseParameters (pp); alertThread.start ();

  43. Real-Time Java Programming RTSJ: Release Characteristics Issues // Analysis Tool Code, Revisited public class AlertThreadAdapter implements javax.realtime.Schedulable { /* we can & should get/set release parameters, scheduling parameters, memory parameters, ... */ public void run () {addToFeasibility (); javax.realtime.RealtimeThread t = (javax.realtime.RealtimeThread) Thread.currentThread (); for (;;) { t.waitForNextPeriod (); // respect advertised cost, period times pipeline.sendAlerts (); } } }

  44. actual execution cost projected execution cost execution finished (late) deadline Real-Time Java Programming RT Issues: Release Failures • Release characteristics advertise how threads are projected to behave • However, differences between projected and actual behavior can lead to unexpected failures • Need to be able to detect (and if possible handle) release failures • Cost overruns • Deadline misses Time

  45. Real-Time Java Programming RTSJ: Release Failure Issues public class CostOverrunEventHandler extends javax.realtime.AsyncEventHandler { public void handleAsyncEvent() {/* ... */}} public class DeadlineMissEventHandler extends javax.realtime.AsyncEventHandler { public void handleAsyncEvent() {/* ... */}} javax.realtime.PeriodicParameters pp = new javax.realtime.PeriodicParameters (null, // start immediately, period, cost, null, // deadline = period end new CostOverrunEventHandler (), new DeadlineMissEventHandler ()); alertThread.setReleaseParameters (pp); alertAdapter.setReleaseParameters (pp); alertThread.start (); • Differences between projected and expected behavior result in release failures • Execution overruns • Deadline misses • Can install a handler for each release characteristics instance to at least record, and possibly correct, failures

  46. executing Real-Time Java Programming RT Issues: Scheduling • Priorities • Need sufficient unique priority levels • Preemptive scheduling • Need well defined and appropriate semantics • Fairness among threads is not usually a Real-Time concern (FIFO vs. RR) • But may be useful • Feasibility • Admission control, certification/testing runnable scheduler blocked

  47. Real-Time Java Programming RTSJ: Scheduling Issues // Analysis Tool Code, Revisited javax.realtime.PriorityScheduler psched = (javax.realtime.PriorityScheduler) javax.realtime.Scheduler.getDefaultScheduler (); javax.realtime.PriorityParameters high = new javax.realtime.PriorityParameters (psched.getMaxPriority ()); javax.realtime.PriorityParameters med = new javax.realtime.PriorityParameters (psched.getNormPriority ()); try { alertThread.setSchedulingParameters (high); pipelineThread. setSchedulingParameters (med); } catch (java.lang.IllegalArgumentException e) {/* ... */} alertThread.start (); pipelineThread.start (); • Release characteristics give control over threads • Scheduling addresses how to manage those threads • Priority, preemption • Feasibility

  48. Real-Time Java Programming RTSJ: Scheduling Issues // Analysis Tool Code, Revisited public class StoreThreadAdapter implements javax.realtime.Schedulable {/* ... */ public void run () { javax.realtime.PriorityScheduler psched = (javax.realtime.PriorityScheduler) javax.realtime.Scheduler.getDefaultScheduler (); try { javax.realtime.PriorityParameters pp = new javax.realtime.PriorityParameters (psched.getMinPriority ()); setSchedulingParameters (pp); javax.realtime.RealtimeThread t = (javax.realtime.RealtimeThread) Thread.currentThread (); t.setSchedulingParameters (pp); } catch (java.lang.IllegalArgumentException e) {/* ... */} store.annotateAlert (alert); } }

  49. running outside block blocked at guard running inside block Real-Time Java Programming RT Issues: Synchronization • Risk of unbounded priority inversions • Canonical high, low, middle scenario • Priorities can uncover or exacerbate “bad” executions of existing race conditions • Horstmann & Cornell, ”Core Java 2” • Need well defined thread and locking semantics waiting (blocked) on a condition variable synchronized block high middle low priority key:

  50. Real-Time Java Programming RTSJ: Synchronization Issues • Real-time threads at different priorities share resources • However, this presents new real-time issues • Priority inversions • Need additional mechanisms to ensure priority-safe sharing • Monitor Control • Methods wait and notifyAll still work (avoid notify unless absolutely sure OK) • But, add overhead • Non-blocking R/W queues: thread glue // Solution: Monitor Control javax.realtime.MonitorControl.setMonitorControl (new javax.realtime.PriorityInheritance ()); // Solution: wait-free queues public class StoreThreadAdapter implements javax.realtime.Schedulable { /* ... */ private javax.realtime.WaitFreeDequeue dequeue; /* ... */ }

More Related