Chapter 10 |
||
Multithreading
Multitasking is the ability of an Operating system to run several different programs at the same time. All the programs are held in memory together and each is allowed to run for a certain period, giving the impression of parallel activity. For example, one program may run while other programs are waiting for a peripheral device to work, or for input from an operator. Multithreading means executing two or more threads or sections of a program simultaneously. A thread is a separate path of execution. In other words, a thread is an independently running subtask. Multithreading is extremely useful in creating a responsive user interface. For example, a browser allows a user to view another page while it is downloading data. This chapter shows two examples. The first example does not create any threads. The source code needed for the first example is stored in the examples\Singlethread directory. The "Singlethread" directory contains the following files:
Remote InterfaceListing 10.1 SingleThreadInterfaceimport java.rmi.*; //remote interface public interface SingleThreadInterface extends Remote { //remote method public String dangerousLoop() throws RemoteException; } The remote interface declares only one method that returns a String object.
|
||
|
||
Copyright © 2001 www.universalteacher.com |
||