Chapter 2: Threads and Program Contexts

 < Day Day Up > 



2.1 Introduction

Concurrent programs have some very different properties from the more common procedural programs with which traditional programmers are familiar. For example, if a procedural program is run repeatedly with the same input, one rightly expects the same result each time, which is nice because a program can be shown to be correct for at least the limited number of cases tested. It also means that any bugs will be reproducible and will occur each time the program is run. The same is not true of concurrent programs, where a program that is run repeatedly can legitimately produce a different answer each time.

This chapter explains what is happening while a program, either procedural or concurrent, is executing. Once the mystery of how a program works is revealed, the reasons why things happen the way they do should be much clearer. This understanding will be used to show how such mechanisms as synchronized blocks and wait and notify methods can be used to control concurrency in a program.

This chapter also introduces the mechanism in Java for creating an asynchronous activity, the thread, and describes how a thread differs from a process. This difference will be used to provide an overview of how the current generation of Web servers is implemented. Some problems unique to concurrent programming are then identified and solved. These problems involve safety (if it finishes, does it get the correct answer?) and liveness (does the program finish?) and are affected by the presence or absence of race conditions and deadlock.



 < Day Day Up > 



Creating Components. Object Oriented, Concurrent, and Distributed Computing in Java
The .NET Developers Guide to Directory Services Programming
ISBN: 849314992
EAN: 2147483647
Year: 2003
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net