|
|
|
|
Why Do We Need Thread Coordination?Threads are often interdependent. That is, one thread may depend on another thread (or several other threads) to perform an operation or service a request. A common problem is when a user requests a program to do something (such as a time-consuming calculation, or a complex database query, or some other process that takes time). Typically, the user interacts with the graphical user interface provided by the Java program. If the requested operation were to be performed in the same thread as the user interface, the user interface would become non-responsive. (I'm sure you've encountered programs that have done this to you!). In Java, it is easy to create a thread and do the time-consuming operation in that thread, thereby freeing up the user interface thread to remain responsive. But this introduces another problem: Once the long-running operation has completed, how does it notify the user interface thread that the work is done, so that the appropriate updates may be made to the user interface? This is just one example of how two threads have a need to coordinate with each other.
|
| The page was last updated February 19, 2008 |