Thursday
Java ProgrammingConcurrency—State Models & Java Programs
Java Programs
- Concurrency—State Models & Java Programs
- The Modeling Approach Java Programs
Between June 1985 and January 1987, a computerized radiation therapy machine called Therac-25 caused six known accidents involving massive overdoses with follow-on deaths and serious injuries. Although most accidents are systemic involving complicated interactions between various components and actions, and Therac-25 is not an exception in this respect, concurrent programming errors played an vital part in these six accidents. Race conditions between different concurrent actions in the control program resulted in occasional erroneous control outputs. Furthermore, the sporadic nature of the errors caused by faulty concurrent programs contributed to the falter in recognizing that here was a problem. The designers of the Therac-25 software seemed largely unaware of the principles and practice of concurrent programming.
The wide acceptance of Java with its in-built concurrency constructs means that concurrent programming is no longer restricted to the underground of programmers caught up in operating systems and embedded real-time applications. Concurrency is helpful in a wide range of applications everywhere responsiveness and throughput are issues. While most programmers are not engaged in the implementation of safety critical systems such as Therac-25, increasing numbers are using concurrent programming constructs in less esoteric applications. Errors in these applications and systems may not be frankly life-threatening but they adversely affect our quality of life and may have severe financial implications. An understanding of the principles of concurrent programming and an appreciation of how it is practiced are an essential part of the education of computing science undergraduates and of the background of software engineering professionals. The pervasive nature of computing and the Internet makes it also an vital topic for those whose primary activity may not be computing but who write programs none the less.
Concurrent Programs
Most complicated systems and tasks that recommend itself in the physical world can be broken down into a set of simpler actions. For example, the actions caught up in building a house include bricklaying, cabinetmaking, plumbing, electrical installation and roofing. These actions do not always recommend itself exactingly sequentially, one after the other, but can overlap and take place concurrently. For example, the plumbing and wiring in a new house can be installed at the same time. The activity described by a computer program can also be subdivided into simpler actions, each described by a subprogram. In traditional sequential programs, these subprograms or procedures are executed one after the other in a fixed order determined by the program and its input. The execution of one procedure does not overlap in time with another. In concurrent programs, computational actions are permitted to overlap in time and the subprogram executions describing these actions proceed concurrently.
The execution of a program (or subprogram) is termed a administer and the execution of a concurrent program thus consists of multiple processes. As we see later, concurrent execution does not require multiple processors. Interleaving the instructions from multiple processes on a single processor can be used to simulate concurrency, charitable the illusion of parallel execution. Of course, if a computer has multiple processors then the instructions of a concurrent program can really be executed in parallel very than life interleaved.
Structuring a program as a set of concurrent actions or processes has many advantages. For programs that interact with the environment to control some physical system, the parallelism and concurrency in that system can be reflected in the control program structure. Concurrency can be used to speed up response to user interaction by offloading time-consuming tasks to separate processes. Throughput can be superior by using multiple processes to manage communication and device latencies. These advantages are illustrated in detail in next article. But, the advantages of concurrency may be offset by the increased complexity of concurrent programs. Administration this complexity and the principles and techniques necessary for the construction of well-behaved concurrent programs is the main subject matter of this blog.
In order to illustrate the need for a rigorous approach to concurrent program design and implementation, let us deliberate an example.
Deliberate an automobile cruise control system that has the following requirements. It is controlled by three buttons: resume, on and off (Figure 1.1). When the engine is running and on is pressed, the cruise control system records the current speed and maintains the car at this speed. When the accelerator, brake or off is pressed, the cruise control system disengages but retains the speed setting. If resume is pressed, the system accelerates or de-accelerates the car back to the previously recorded speed.
Figure 1.1: Cruise control system.

Our task is to grant a Java program that satisfies the individual requirements and behaves in a safe style. How must we design such a program? What software processes must we construct and how must we structure them to form a program? How can we ensure that our program provides the behavior that we require while avoiding unsafe or undesirable behavior?
Given no guidance, we may be tempted simply to use previous design experience and construct the program as best as we can, using the appropriate Java concurrency constructs. To test the cruise control software, we could construct a simulation environment such as that illustrated in Figure 1.2. The website that accompanies this blog contains this environment as an interactive Java applet for use and experimentation (http://www.wileyeurope.com/college/magee). The buttons at the bottom of the show can be used to control the simulation: to switch the engine on or off; to resume or turn the cruise control system on or off ; and to push the accelerator or brake (simulated by repeatedly pressing the relevant pin).
Figure 1.2: Simulation of the cruise control system.

The behavior of the system can be checked using particular scenarios such as the following:
- Is the cruise control system enabled after the engine is switched on and the on pin is pressed?
- Is the cruise control system disabled when the brake is pressed?
- Is the cruise control system enabled when resume is then pressed?
But, hard such software is hard, as here are many possible scenarios. How do we know when we have conducted a sufficient number of test scenarios?
For instance, what happens in the dodgy event that the engine is switched off while the cruise control system is still enabled? The system behaves as follows. It retains the cruise control setting, and, when the ignition is again switched on, the car accelerates so as to resume the previous speed setting!
Would hard have learned that this perilous behavior is present in the system? Perhaps, but in general hard is extremely hard for concurrent programs as it relies on executing the particular sequence of actions and actions that cause a problem. In view of the fact that concurrent actions may recommend itself in any order, the problem sequences may never recommend itself in the test environment, but may only show up in the deployed system, as with the Therac-25 machine.
Here must be a better way to design, check and construct concurrent programs!
Post Tags: Basic of Java Programming, Java Programming
Related Posts
- The Modeling Approach Java Programs
- More About Multithreading in Java
- The Basics of Multiple Threads in Java
- Basics of Java Programming
- Tomcat Performance Tuning
- Event Delegation in JavaScript
- Several Words About The Advantages Of Tablet PCs
- Objects of Java
- Inheritance and Aggregation in Java Language
- Being Aware Of The Advantages Of Purchasing Mobile Phones On The Internet
Popular
- iPhone or iPod Touch, Which One Should You Choose? - 47,823 views
- Introduction to Facebook - 26,724 views
- 7 Top Twitter Topic Trackers - 16,421 views
- Introduction of Hacking Methodology - 15,070 views
- Google Hacking Keywords - 12,019 views
- LG BD390 Wi-Fi Blu-ray Player Review: So Packed You’ll Forget About Blu [Review] - 10,109 views
- BlackBerry Curve 3G: A Familiar, Powerful Phone - 9,842 views
- Complete Guide to Web Site Marketing - 9,809 views
- Microsoft’s Zune HD Wiill Have OLED, HD Radio - 9,320 views
- Photo Album and Printing Services - 8,979 views
Featured Articles
- The Elements of the Facebook Platform
- Introducing the Facebook Platform
- Social Skills Today Are Being Lost
- GibBook – Gibraltar Own Social Network Site
- 7 Deadly Twitter Sins
- Introduction to Facebook
- Google’s Wave: Many Online Apps in One Tool
- App Mapping War Casualties Debuts for Memorial Day Weekend
- Google@Omgili Mashes Traditional Web Search With Social Buzz
- Capital Factory: Austin-Based Incubator (RWS Interview)
Recent Posts
- Tweet via something
- Lightroom Review And Other Phot
- Several Words About The Advantages Of Tablet PCs
- Dissimilar Positive Features Of Table Computers
- Digi Link Doctor
- Why You Need Professional SEO Software
- Automated SEO Tools For Online Business
- How To Choose The Best Tablet PC
- Tablet PC – The Latest Computer Technology
- Tablet PCs Compared To Laptops