Chapter 10

Multithreading

 

 

Universal TeacherMultitasking 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:

  • SingleThreadInterface.java
  • SingleThreadImpl.java
  • SingleThreadClient.java
  • Compile.bat
  • Rmicompile.bat
  • RunServer.bat
  • RunClient.bat

Remote Interface

Listing 10.1 SingleThreadInterface

import 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.

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com